-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic-mk2.py
160 lines (142 loc) · 5.27 KB
/
static-mk2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import os, discord, time, random
import asyncio
import youtube_dl
from gtts import gTTS
from dotenv import load_dotenv
from datetime import date
from discord.ext import commands
youtube_dl.utils.bug_reports_message = lambda: ''
ytdl_format_options = {
'format': 'bestaudio/best',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
'source_address': '0.0.0.0' # bind to ipv4 since ipv6 addresses cause issues sometimes
}
ffmpeg_options = {
'options': '-vn'
}
ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
class YTDLSource(discord.PCMVolumeTransformer):
def __init__(self, source, *, data, volume=0.5):
super().__init__(source, volume)
self.data = data
self.title = data.get('title')
self.url = ""
@classmethod
async def from_url(cls, url, *, loop=None, stream=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
if 'entries' in data:
# take first item from a playlist
data = data['entries'][0]
filename = data['title'] if stream else ytdl.prepare_filename(data)
return filename
#
#
#
intents = discord.Intents().all()
client = discord.Client(intents=intents)
bot = commands.Bot(
command_prefix=commands.when_mentioned_or("!"),
description="Static - 0.2",
intents=intents,
activity = discord.Game(name="The Humans Are Dead")
)
@bot.command(name="bword", help="backwards")
async def bword(ctx, word):
await ctx.send(f'{word[::-1]}')
#--------------
@bot.command(name='join', help='Tells the bot to join the voice channel')
async def join(ctx):
if not ctx.message.author.voice:
await ctx.send("{} is not connected to a voice channel".format(ctx.message.author.name))
return
else:
channel = ctx.message.author.voice.channel
await channel.connect()
@bot.command(name='leave', help='To make the bot leave the voice channel')
async def leave(ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_connected():
await voice_client.disconnect()
else:
await ctx.send("The bot is not connected to a voice channel.")
@bot.command(name='play_song', help='To play song')
async def play(ctx, url):
if not ctx.message.author.name=="AdrianS":
await ctx.send('ACCESS DENIED')
return
try :
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
await ctx.send("Sure thing.. one sec, Downloading that file now")
filename = await YTDLSource.from_url(url, loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(executable="ffmpeg", source=filename))
await ctx.send('**Now playing:** {}'.format(filename))
except:
await ctx.send("The bot is not connected to a voice channel.")
@bot.command(name='pause', help='This command pauses the song')
async def pause(ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_playing():
await voice_client.pause()
else:
await ctx.send("The bot is not playing anything at the moment.")
@bot.command(name='resume', help='Resumes the song')
async def resume(ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_paused():
await voice_client.resume()
else:
await ctx.send("The bot was not playing anything before this. Use play_song command")
@bot.command(name='stop', help='Stops the song')
async def stop(ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_playing():
await voice_client.stop()
else:
await ctx.send("The bot is not playing anything at the moment.")
@bot.command(name='status', help='Static Status')
async def status(ctx):
if ctx.message.guild.voice_client.is_connected():
await say(ctx, 'Hello, My name is Static')
else:
async with ctx.typing():
await ctx.send('Hello, My name is Static')
@bot.command(name='hackers', help='Play Hackers OST')
async def hackers(ctx):
async with ctx.typing():
await ctx.send('Searching.. Please wait.')
try:
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
filename = await YTDLSource.from_url('https://www.youtube.com/watch?v=JEyEkbOlMfA', loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(executable="ffmpeg", source=filename))
await ctx.send("Playing Hackers OST {}".format(filename))
except:
await ctx.send("I am not connected to a voice channel.")
#-----------------
def say(ctx, text):
filename = "static.mp3"
response = gTTS(text=text, lang="en", slow=False)
response.save(filename)
server = ctx.message.guild
voice_channel = server.voice_client
voice_channel.play(discord.FFmpegPCMAudio(executable="ffmpeg", source=filename))
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print('------')
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
if __name__ == "__main__":
bot.run(TOKEN)