-
Notifications
You must be signed in to change notification settings - Fork 8
/
bot.py
255 lines (211 loc) · 8.63 KB
/
bot.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
import discord
import os
import io
import traceback
import sys
import time
import datetime
import asyncio
import random
import aiohttp
import random
import textwrap
import inspect
from contextlib import redirect_stdout
from discord.ext import commands
import json
bot = commands.Bot(command_prefix=commands.when_mentioned_or('*'),description="The revamped dat banana bot made by dat banana boi#1982.\n\nHelp Commands",owner_id=277981712989028353)
bot._last_result = None
bot.remove_command("help")
bot.load_extension("cogs.math")
bot.load_extension("cogs.mod")
bot.load_extension("cogs.utility")
bot.load_extension("cogs.fun")
bot.load_extension("cogs.info")
bot.load_extension("cogs.developer")
bot.load_extension("cogs.cr")
bot.load_extension("cogs.help")
bot.load_extension("cogs.coc")
bot.load_extension("cogs.lol")
def cleanup_code(content):
# remove ```py\n```
if content.startswith('```') and content.endswith('```'):
return '\n'.join(content.split('\n')[1:-1])
return content.strip('` \n')
def dev_check(id):
with open('data/devs.json') as f:
devs = json.load(f)
if id in devs:
return True
return False
@bot.event
async def on_ready():
print('Bot is online, and ready to ROLL!')
while True:
await bot.change_presence(game=discord.Game(name=f"with {len(bot.guilds)} servers!"))
await asyncio.sleep(15)
await bot.change_presence(game=discord.Game(name="using *help!"))
await asyncio.sleep(15)
await bot.change_presence(game=discord.Game(name="in v6.0, BETA."))
await asyncio.sleep(15)
@bot.event
async def on_guild_join(guild):
lol = bot.get_channel(392443319684300801)
em = discord.Embed(color=discord.Color(value=0x00ff00))
em.title = "dat banana bot has arrived in a new server!"
em.description = f"Server: {guild}"
await lol.send(embed=em)
await guild.channels[0].send(f"Hiya, guys in **{guild.name}**! Thanks for welcoming me! I am dat banana bot, a gud Discord bot. Try me out by typing *help!")
@bot.event
async def on_guild_remove(guild):
lol = bot.get_channel(392443319684300801)
em = discord.Embed(color=discord.Color(value=0xf44242))
em.title = "dat banana bot has been removed from a server."
em.description = f"Server: {guild}"
await lol.send(embed=em)
@bot.event
async def on_member_join(member):
f = open("data/welcomemsg.json").read()
x = json.loads(f)
channel = x[str(member.guild.id)]
if channel is False:
pass
else:
lol = bot.get_channel(channel)
await lol.send(f"Hello {member.mention}! Welcome to **{member.guild.name}**, have a great time!")
@bot.event
async def on_command_error(ctx, error):
em = discord.Embed(color=discord.Color(value=0xf44e42), title='An error occurred.')
if isinstance(error, commands.NotOwner):
em.description = 'Not my daddy! This command is for the owner only.'
if isinstance(error, commands.MissingPermissions):
em.description = 'You are missing permissions required to run this command.'
if isinstance(error, commands.CommandNotFound):
return
return await ctx.send(embed=em)
@bot.command(name='presence')
@commands.is_owner()
async def _set(ctx, Type=None,*,thing=None):
"""What AM I doing?!?!?!"""
if Type is None:
await ctx.send('Do it right, plz! Usage: *presence [game/stream] [msg]')
else:
if Type.lower() == 'stream':
await bot.change_presence(game=discord.game(name=thing,type=1,url='https://www.twitch.tv/a'),status='online')
await ctx.send(f'Aye aye, I am now streaming {thing}!')
elif Type.lower() == 'game':
await bot.change_presence(game=discord.game(name=thing))
await ctx.send(f'Aye aye, I am now playing {thing}!')
elif Type.lower() == 'clear':
await bot.change_presence(game=None)
await ctx.send('Aye aye, I am not playing anything, anymore!')
else:
await ctx.send('Want me to do something? YOU do it right first. Usage: *presence [game/stream] [msg]')
@bot.command()
async def bug(ctx, *, msg:str):
"""Got a PROB? Tell us about it... """
lol = bot.get_channel(373917178547929088)
color = discord.Color(value=0x00ff00)
em=discord.Embed(color=color, title="Bug reported!")
em.description = f"Bug: {msg}"
em.set_footer(text=f"Bug sent by {ctx.message.author.name}")
await ctx.send("Thanks for reporting that bug! :bug: We will get back to you ASAP.")
@bot.command()
async def say(ctx, *, message: str):
'''I say what you want me to say. Oh boi...'''
await ctx.message.delete()
await ctx.send(message)
@bot.command()
async def ping(ctx):
"""Premium ping pong giving you a websocket latency."""
color = discord.Color(value=0x00ff00)
em = discord.Embed(color=color, title='PoIIIng! Your supersonic latency is:')
em.description = f"{bot.latency * 1000:.4f} ms"
em.set_footer(text="Psst...A heartbeat is 27 ms!")
await ctx.send(embed=em)
@bot.command()
async def invite(ctx):
"""Allow my bot to join the hood. YOUR hood."""
await ctx.send("Lemme join that hood -> https://discordapp.com/oauth2/authorize?client_id=388476336777461770&scope=bot&permissions=2146958591")
@bot.command(name='discord')
async def _discord(ctx):
"""We have an awesome hood to join, join now!"""
await ctx.send("Your turn to join the hood -> https://discord.gg/wvkVknA")
@bot.command(name='eval')
async def _eval(ctx, *, body):
"""Evaluates python code"""
if not dev_check(ctx.author.id):
return await ctx.send("You cannot use this because you are not a developer.")
env = {
'ctx': ctx,
'channel': ctx.channel,
'author': ctx.author,
'guild': ctx.guild,
'message': ctx.message,
'_': bot._last_result,
}
env.update(globals())
body = cleanup_code(body)
stdout = io.StringIO()
err = out = None
to_compile = f'async def func():\n{textwrap.indent(body, " ")}'
def paginate(text: str):
'''Simple generator that paginates text.'''
last = 0
pages = []
for curr in range(0, len(text)):
if curr % 1980 == 0:
pages.append(text[last:curr])
last = curr
appd_index = curr
if appd_index != len(text) - 1:
pages.append(text[last:curr])
return list(filter(lambda a: a != '', pages))
try:
exec(to_compile, env)
except Exception as e:
err = await ctx.send(f'```py\n{e.__class__.__name__}: {e}\n```')
return await ctx.message.add_reaction('\u2049')
func = env['func']
try:
with redirect_stdout(stdout):
ret = await func()
except Exception as e:
value = stdout.getvalue()
err = await ctx.send(f'```py\n{value}{traceback.format_exc()}\n```')
else:
value = stdout.getvalue()
if ret is None:
if value:
try:
out = await ctx.send(f'```py\n{value}\n```')
except:
paginated_text = paginate(value)
for page in paginated_text:
if page == paginated_text[-1]:
out = await ctx.send(f'```py\n{page}\n```')
break
await ctx.send(f'```py\n{page}\n```')
else:
bot._last_result = ret
try:
out = await ctx.send(f'```py\n{value}{ret}\n```')
except:
paginated_text = paginate(f"{value}{ret}")
for page in paginated_text:
if page == paginated_text[-1]:
out = await ctx.send(f'```py\n{page}\n```')
break
await ctx.send(f'```py\n{page}\n```')
if out:
await ctx.message.add_reaction('\u2705') # tick
elif err:
await ctx.message.add_reaction('\u2049') # x
else:
await ctx.message.add_reaction('\u2705')
f = open("data/apikeys.json").read()
x = json.loads(f)
try:
bot.run(x['bottoken'])
except Exception as e:
print("Could not start the bot. Check the token.")