-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
216 lines (192 loc) · 7.9 KB
/
main.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import time
import discord
import json
import random
from discord import app_commands
from discord.ext import commands
from discord.errors import *
import datetime
import string
import yt_dlp
import asyncio
bot = commands.Bot(command_prefix=".", intents = discord.Intents.all())
activity: str
startTime = time.time()
blockedWords = []
dogwaterWords = []
email = ["gmail.com", "hotmail.com", "outlook.com", "oatlocker.com", "yahoo.co.nz", "oatlocker.com", "deeznuts.com", "gmail.com", "yahoo.co.nz", "outlook.com", "gmail.com"]
token: str
yt_dlp.utils.bug_reports_message = lambda: ''
ytdl_format_options = {
'format': 'bestaudio/best',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': False,
'no_warnings': True,
'default_search': 'auto',
'source_address': '0.0.0.0'
}
ffmpeg_options = {
'options': '-vn'
}
ytdl = yt_dlp.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:
data = data['entries'][0]
filename = data['title'] if stream else ytdl.prepare_filename(data)
return filename
@bot.tree.command(name='dogwater', description = "Ur dogwater kid")
async def dogwater(interaction: discord.Interaction, user: discord.User):
await interaction.response.send_message(f"{(str (random.choice(dogwaterWords))).format(name = user.mention)}")
@bot.tree.command(name='dmme', description = "Dms you")
async def dmme(interaction: discord.Interaction, what: str):
user = bot.get_user(interaction.user.id)
await user.send(what)
await interaction.response.send_message(f"Done", ephemeral=True)
@bot.tree.command(name='heck', description = "Heck")
async def heck(interaction: discord.Interaction, user: discord.User):
letters: str = ""
for x in range(10):
letters = letters + random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits)
email1 = random.choice(email)
heck_embed=discord.Embed(title=f"Hecked {user.name}", color=discord.Color.blue())
heck_embed.add_field(name='Email', value=f"{user.name}{letters[0]}{letters[1]}{letters[2]}{letters[3]}@{email1}", inline=True)
heck_embed.add_field(name='Password', value=f"{letters}", inline=True)
await interaction.response.send_message(embed=heck_embed)
@bot.tree.command(name='rat', description = "Responds with rat?")
async def rat(interaction: discord.Interaction):
await interaction.response.send_message("Rat?")
@bot.tree.command(name='latency', description = "Check the bots latency to discord")
async def latency(interaction: discord.Interaction):
await interaction.response.send_message(f"The bots latency is {round(bot.latency * 1000)}ms")
@bot.tree.command(name='join', description = "Joins vc")
async def join(interaction: discord.Interaction):
if interaction.user.voice is not None:
vc = interaction.user.voice.channel
voice = await vc.connect()
await interaction.response.send_message("Joining voice channel")
else:
await interaction.response.defer(ephemeral=True)
await interaction.followup.send("You are not in a voice channel.")
return
@bot.tree.command(name='play', description = "Plays music")
async def play(interaction: discord.Interaction, song: str):
try :
await interaction.response.defer(thinking = True)
guild = interaction.guild
voice_channel = guild.voice_client
try:
filename = await YTDLSource.from_url(song, loop=bot.loop)
except:
await interaction.followup.send('Failed to download music')
try:
voice_channel.play(discord.FFmpegPCMAudio(source=filename))
music_name: str = filename
music_name = music_name.replace("-", " ")
music_name = music_name.replace("_", " ")
music_name = music_name.replace(".webm", "")
music_embed=discord.Embed(title='**Now playing:** {}'.format(music_name), color=discord.Color.blue())
await interaction.followup.send(embed=music_embed)
except:
await interaction.followup.send('Failed to play music')
except:
await interaction.followup.send("The bot is not connected to a voice channel.")
@bot.tree.command(name='leave', description = "Leaves vc")
async def leave(interaction: discord.Interaction):
guild = interaction.guild
vc = guild.voice_client
if vc:
vc.cleanup()
await vc.disconnect()
await interaction.response.send_message('Leaving voice channel')
else:
await interaction.response.send_message("The bot isn't in the voice channel")
@bot.tree.command(name='pause', description = "Pauses music")
async def pause(interaction: discord.Interaction):
guild = interaction.guild
voice_channel = guild.voice_client
try :
await interaction.response.send_message("Paused the music.")
voice_channel.pause()
except:
await interaction.response.send_message("The bot is not playing anything at the moment.")
@bot.tree.command(name='uptime', description = "Gets the bots uptime")
async def uptime(interaction: discord.Interaction):
await interaction.response.send_message("The bots uptime is {}".format(get_uptime()))
@bot.tree.command(name='resume', description = "Resumes music")
async def resume(interaction: discord.Interaction):
guild = interaction.guild
voice_channel = guild.voice_client
try:
await interaction.response.send_message("Resumed the music.")
await voice_channel.resume()
except:
await interaction.response.send_message("The bot is not playing anything at the moment.")
@bot.tree.command(name='stop_music', description = "Stops music")
async def stop_music(interaction: discord.Interaction):
guild = interaction.guild
voice_channel = guild.voice_client
if voice_channel.is_playing():
await interaction.response.send_message("Stopping the music.")
voice_channel.stop()
else:
await interaction.response.send_message("The bot is not playing anything at the moment.")
@bot.event
async def on_ready():
global activity
if not activity == None:
activity = discord.Game(name=activity)
await bot.change_presence(status=discord.Status.online, activity=activity)
try:
synced = await bot.tree.sync()
print(f'Synced {len(synced)} commands')
except Exception as e:
print(e)
def get_uptime():
return str(datetime.timedelta(seconds=int(round(time.time()-startTime))))
def logout():
bot.close()
print("Logging out bot")
def main():
global activity
with open('config.json') as f:
data = json.load(f)
token = data["token"]
activity = data["Activity"]
for dogwaterStr in data['dogwater']:
dogwaterWords.append(dogwaterStr)
if token == None or token == "":
print("No token, please provide a bot token")
return
try:
bot.run(token)
except LoginFailure:
print("Login failure.")
exit()
except RateLimited as e:
print(f"Rate limited. Try again in {e.retry_after}")
exit()
except HTTPException as e:
print(f"HTTP request error {e.status}.")
exit()
except GatewayNotFound:
print("Gateway not found. The gateway to connect to discord was not found.")
exit()
except InvalidData:
print("Invalid Data.")
except ConnectionClosed:
print("Connection Closed.")
if __name__ == "__main__":
main()