forked from aveao/AveBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavebot.py
executable file
·323 lines (306 loc) · 21 KB
/
avebot.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import discord
import asyncio
import urllib.request
from pathlib import Path
import socket
import datetime
import traceback
import re
import os
import time
import subprocess
import socket
import json
import requests
client = discord.Client()
botowner = "137584770145058817"
def get_mods_list():
try:
with open("modslist", "r") as modfile:
modfilething = modfile.read().split("\n")
return modfilething
except FileNotFoundError:
avelog("No modslist file found! Please create one or run >addmod")
return []
except Exception:
avelog(traceback.format_exc())
def get_privileged_list():
try:
with open("privlist", "r") as privfile:
privfilething = privfile.read().split("\n")
return privfilething
except FileNotFoundError:
avelog("No privlist file found! Please create one or run >addpriv")
return []
except Exception:
avelog(traceback.format_exc())
def get_ban_list():
try:
with open("banlist", "r") as banfile:
banfilething = banfile.read().split("\n")
return banfilething
except FileNotFoundError:
avelog("No banlist file found! Please create one.")
return []
except Exception:
avelog(traceback.format_exc())
def get_git_revision_short_hash():
return str(subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip()).replace("b'","").replace("'","")
def avelog( content ):
try:
st = str(datetime.datetime.now()).split('.')[0]
text = st + ': ' + content
print(text)
with open("log.txt", "a") as myfile:
myfile.write(text+"\n")
return
except Exception:
exit()
@client.event
async def on_ready():
st = str(datetime.datetime.now()).split('.')[0]
avelog('Logged in as')
avelog(client.user.name)
avelog(client.user.id)
avelog('------')
try:
time.sleep(3)
await client.change_presence(game=discord.Game(name='run >help'))
em = discord.Embed(title='AveBot initialized!', description='Git hash: `'+get_git_revision_short_hash()+'`\nHostname: '+socket.gethostname()+'\nLocal Time: '+st+'\nLogs are attached.', colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(discord.Object(id='305715263951732737'), embed=em)
await client.send_file(discord.Object(id='305715263951732737'), "log.txt")
open('log.txt', 'w').close() # Clears log
except Exception:
avelog(traceback.format_exc())
exit()
@client.event
async def on_message(message):
try:
if message.content.lower().startswith('ok'):
await client.add_reaction(message, "🆗")
elif message.content.lower().startswith('hot'):
await client.add_reaction(message, "🔥")
elif message.content.lower().startswith('cool'):
await client.add_reaction(message, "❄")
if "🤔" in message.content: # thinking
await client.add_reaction(message, "🤔")
if message.content.startswith('>'):
if (not str(message.author.id) in get_ban_list()):
if (message.channel.is_private):
avelog(message.author.name + " (" + message.author.id + ") ran " + message.content + ' on PMs.')
else:
avelog(message.author.name + " (" + message.author.id + ") ran " + message.content + ' on '+message.channel.name+' at '+message.server.name+'.')
if message.content.startswith('>howmanymessages'):
counter = 0
tmp = await client.send_message(message.channel, 'Calculating messages...')
async for log in client.logs_from(message.channel, limit=10000):
if log.author == message.author:
counter += 1
await client.edit_message(tmp, 'You have sent {} messages out of the last 10000 in this channel.'.format(counter))
elif message.content.startswith('>geninvite'):
inviteurl = await client.create_invite(message.channel,max_uses=1)
em = discord.Embed(title='Invite ready!', description='Here you go: ' + inviteurl.url + ' \n(Note: This invite is for THIS server/channel, not any other server. Please contact ao#5755 if you suspect that it is being abused and want to learn the identity of the person who abused this function.)', colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>addavebot'):
inviteurl = discord.utils.oauth_url("305708836361207810")
em = discord.Embed(title='Invite ready!', description='Here you go: ' + str(inviteurl), colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>whoami'):
em = discord.Embed(title=':thinking:', description='You are `' + message.author.name + "` (`" + message.author.id + '`)', colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>contact '):
contactcontent = message.content.replace(">contact ", "")
em = discord.Embed(title='Contact received!', description='**Message by:** '+str(message.author) + " (" + message.author.id + ')\n on '+message.channel.name+' at '+message.server.name+'\n**Message content:** '+contactcontent, colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(discord.Object(id='305857608378613761'), embed=em)
em = discord.Embed(title='Contact sent!', description='Your message has been delivered to the developers.', colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>bigly '):
letters = re.findall(r'[a-z0-9 ]', message.content.replace(">bigly ", "").lower())
biglytext = ''
ri = 'regional_indicator_'
for letter in letters:
biglytext = biglytext+ ":"+ri+str(letter)+": "
em = discord.Embed(title='Biglified', description=biglytext.replace(ri+"0","zero").replace(ri+"1","one").replace(ri+"2","two").replace(ri+"3","three").replace(ri+"4","four").replace(ri+"5","five").replace(ri+"6","six").replace(ri+"7","seven").replace(ri+"8","eight").replace(ri+"9","nine").replace(":"+ri+" :","\n"), colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/bigly.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>helplong'):
await client.send_file(message.channel, "helplong.md", content="Here's the long help file:")
elif message.content.startswith('>help'):
helpfile = open("help.md", "r")
em = discord.Embed(title='Hello from AveBot!', description='This bot is developed and owned by ao#5755 and is currently running on `'+socket.gethostname()+'` server.\nGit hash: `'+get_git_revision_short_hash()+'`, repo: https://github.com/ardaozkal/AveBot\nInvite link is on the github repo.\n'+helpfile.read(), colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>resolve ') or message.content.startswith('>dig '):
resolveto = message.content.replace(">resolve ", "").replace(">dig ", "")
resolved = repr(socket.gethostbyname_ex(resolveto))
em = discord.Embed(title='Resolved ' + resolveto, description='Successfully resolved `' + resolveto + '` to `'+resolved+'`.', colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>ping'):
em = discord.Embed(title=':ping_pong: Pong', colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>trumpsim'):
seed = message.content.split(' ')[1]
response = requests.get("127.0.0.1:2001/reply?q={}".format(seed)).content
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
em = discord.Embed(title="Trump says: '{}'".format(response), colour=0xDEADBF)
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>epoch') or message.content.startswith('>unixtime'):
em = discord.Embed(title="Current epoch time is: **" + str(int(time.time()))+"**.", colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>erdogan') or message.content.startswith('>trump'):
em = discord.Embed(title="DICTATOR DETECTED", colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>!'):
toquery = message.content.replace(">!", "!").replace(" ","+")
output = urllib.request.urlopen("https://api.duckduckgo.com/?q="+toquery+"&format=json&pretty=0&no_redirect=1").read().decode()
j = json.loads(output)
resolvedto = j["Redirect"]
if resolvedto:
messagecont="Bang resolved to: "+resolvedto
await client.send_message(message.channel, content=messagecont)
elif message.content.startswith('>xkcd '):
toquery = message.content.replace(">xkcd", "").replace(" ", "").replace("xkcd.com/", "").replace("https://", "").replace("http://", "").replace("www.", "").replace("m.", "").replace("/", "") #lazy as hell :/
if toquery:
toquery = toquery + "/"
output = urllib.request.urlopen("https://xkcd.com/"+toquery+"info.0.json").read().decode()
j = json.loads(output)
resolvedto = j["img"]
title = j["safe_title"]
alt = j["alt"]
xkcdid = str(j["num"])
date = j["day"]+"-"+j["month"]+"-"+j["year"]+" (DDMMYYYY)"
if resolvedto:
messagecont="**XKCD "+xkcdid+":** `"+title+"`, published on "+date+"\n**Image:** " + resolvedto + "\n**Alt text:** `"+alt+"`\nExplain xkcd: <http://www.explainxkcd.com/wiki/index.php/"+xkcdid+">"
await client.send_message(message.channel, content=messagecont)
elif message.content.startswith('>similar '):
toquery = message.content.replace(">similar ", "")
output = urllib.request.urlopen("https://api.datamuse.com/words?ml="+toquery.replace(" ","+")).read().decode()
j = json.loads(output)
em = discord.Embed(title="Similar word: " + j[0]["word"], description="(more on <http://www.onelook.com/thesaurus/?s="+toquery.replace(" ","_")+"&loc=cbsim>)", colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>typo '):
toquery = message.content.replace(">typo ", "")
output = urllib.request.urlopen("https://api.datamuse.com/words?sp="+toquery.replace(" ","+")).read().decode()
j = json.loads(output)
em = discord.Embed(title="Typo fixed: " + j[0]["word"], description="(more on <http://www.onelook.com/?w="+toquery.replace(" ","+")+"&ls=a>)", colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>soundslike '):
toquery = message.content.replace(">soundslike ", "")
output = urllib.request.urlopen("https://api.datamuse.com/words?sl="+toquery.replace(" ","+")).read().decode()
j = json.loads(output)
em = discord.Embed(title="Sounds like: " + j[0]["word"], description="(more on <http://www.onelook.com/?w="+toquery.replace(" ","+")+"&ls=a>)", colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>rhyme '):
toquery = message.content.replace(">rhyme ", "")
output = urllib.request.urlopen("https://api.datamuse.com/words?rel_rhy="+toquery.replace(" ","+")).read().decode()
j = json.loads(output)
em = discord.Embed(title="Rhymes with: " + j[0]["word"], description="(more on <http://www.rhymezone.com/r/rhyme.cgi?Word="+toquery.replace(" ","+")+"&typeofrhyme=adv&org1=syl&org2=l&org3=y>)", colour=0xDEADBF)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
if message.author.id == botowner:
if message.content.startswith('>exit') or message.content.startswith('>brexit'):
em = discord.Embed(title='Exiting AveBot', description='Goodbye!', colour=0x64dd17)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
exit()
elif message.content.startswith('>pull'):
em = discord.Embed(title='Pulling and restarting AveBot', description='BBIB!', colour=0x64dd17)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
exit()
elif message.content.startswith('>addmod '):
modstoadd = message.mentions
with open("modslist", "a") as modfile:
for dtag in modstoadd:
modfile.write(dtag.id+"\n")
em = discord.Embed(title='Added ' + str(dtag) + '(' + dtag.id + ') as mod.', description='Welcome to the team!', colour=0x64dd17)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>fetchlog'):
await client.send_file(message.channel, "log.txt", content="Here's the current log file:")
#else:
# em = discord.Embed(title="Insufficient Permissions (Owner status needed)", colour=0xcc0000)
# em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
# await client.send_message(message.channel, embed=em)
if message.author.id in get_mods_list():
if message.content.startswith('>addpriv '):
privstoadd = message.mentions
with open("privlist", "a") as privfile:
for dtag in privstoadd:
privfile.write(dtag.id+"\n")
em = discord.Embed(title='Added ' + str(dtag) + '(' + dtag.id + ') as privileged user.', description='Welcome to the team!', colour=0x64dd17)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>ban '):
banstohand = message.mentions
with open("banlist", "a") as banfile:
for dtag in banstohand:
banfile.write(dtag.id+"\n")
em = discord.Embed(title='Banned ' + str(dtag) + '(' + dtag.id + ').', description='(People are idiots)', colour=0x64dd17)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
elif message.content.startswith('>say '):
tosay = message.content.replace(">say ", "")
await client.send_message(message.channel, content=tosay)
#else:
# em = discord.Embed(title="Insufficient Permissions (Mod status needed)", colour=0xcc0000)
# em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
# await client.send_message(message.channel, embed=em)
if message.author.id in get_privileged_list():
if message.content.startswith('>material '):
filename = message.content.split(' ')[1]
if not filename.startswith('ic_'):
filename = "ic_" + filename
if not filename.endswith(('.svg', '.png')):
filename = filename + "_white_48px.svg"
link = "https://storage.googleapis.com/material-icons/external-assets/v4/icons/svg/" + filename
filename = "files/" + filename
my_file = Path(filename)
if not my_file.is_file():
urllib.request.urlretrieve(link, filename);
await client.send_file(message.channel, filename, content=":thumbsup: Here's the file you requested.")
elif message.content.startswith('>dget '):
link = message.content.split(' ')[1]
filename = "files/requestedfile"
urllib.request.urlretrieve(link, filename);
await client.send_file(message.channel, filename, content=":thumbsup: Here's the file you requested.")
elif message.content.startswith('>get '):
link = message.content.split(' ')[1]
filename = "files/" + link.split('/')[-1]
urllib.request.urlretrieve(link, filename);
await client.send_file(message.channel, filename, content=":thumbsup: Here's the file you requested.")
#else:
# em = discord.Embed(title="Insufficient Permissions (Privileged status needed)", colour=0xcc0000)
# em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
# await client.send_message(message.channel, embed=em)
else:
avelog(str(message.author) + " (" + message.author.id + ") ran " + message.content + ' on ' + message.channel.name + ' at ' + message.server.name + ', but is banned.')
em = discord.Embed(title="*Insert sigh* You are banned from using AveBot.", colour=0xcc0000)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
except Exception:
avelog(traceback.format_exc())
em = discord.Embed(title="An error happened", description="It was logged and will be reviewed by developers.", colour=0xcc0000)
em.set_author(name='AveBot', icon_url='https://s.ave.zone/c7d.png')
await client.send_message(message.channel, embed=em)
avelog("AveBot started. Git hash: " + get_git_revision_short_hash())
if not os.path.isdir("files"):
os.makedirs("files")
try:
with open("bottoken", "r") as tokfile:
client.run(tokfile.read().replace("\n",""))
except FileNotFoundError:
avelog("No bottoken file found! Please create one. Join discord.gg/discord-api and check out #faq for more info.")