forked from lucasvianav/discord-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.py
87 lines (73 loc) · 3 KB
/
util.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
import os
import re
from functools import reduce
import requests
from bs4 import BeautifulSoup
# constants
WELCOME_CHANNEL = 'random' # channel in which to send welcome message for new members
MESSAGE_EMOJI = '🐴' # emoji that'll be mainly used to react to user messages
RESPONSE_EMOJI = '🚚' # emoji that'll be used to react to all bot messages
FIXED_COGS = [ # all cogs that aren't from the google sheet
'Reuniões', 'OnMemberJoin', 'Decisions',
'Counters', 'Utilities', 'Birthday'
]
AVAILABLE_REACTIONS = [ # list of reactions that'll be used in poll-like commands
'🤠', '🍉', '💘', '🏂',
'🧨', '🎂', '💣', '🎷', '🛹'
]
VOCATIVES = [ # list of vocatives that'll be used on the welcome message for new members
'anjo', 'consagrado', 'comparsa',
'amigo', 'caro', 'cumpadi', 'bonito',
'campeão', 'tributarista', 'chegado',
'peregrino', 'camponês', 'patrão',
'donatário', 'bacharel', 'iluminado',
'democrata', 'parnasiano', 'vacinado',
'querido', 'barbeiro', 'zé', 'filho'
]
async def reactToResponse(bot, response, emojiList = []):
if not emojiList: emojiList = []
emojiList.insert(0, RESPONSE_EMOJI)
for emoji in emojiList:
try:
await response.add_reaction(emoji)
except:
print(f" [**] There was an error while reacting {emoji} to the response.")
else:
print(f" [**] The reaction {emoji} was successfully added to the response.")
async def reactToMessage(bot, message, emojiList: list):
for emoji in emojiList:
try:
await message.add_reaction(emoji)
except:
print(f" [**] There was an error while reacting {emoji} to the message.")
else:
print(f" [**] The reaction {emoji} was successfully added.")
# downloads the image from a link and returns it's path
def getImage(img: str):
if img.startswith('http'):
try: r = requests.get(img)
except:
print(' [**] There was an error with the image link: ' + img)
img = False
else:
with open('aux.png', 'wb') as f: f.write(r.content)
r.close()
img = 'aux.png'
print(' [**] The image was successfully downloaded.')
else:
print(' [**] There is no image to attach.')
img = False
return img
# Generates cogs based on the sheet's commands
def refreshCogs(bot, hasLoaded=True):
if not os.path.isdir('./cogs'): os.mkdir('./cogs')
# Unloads and then removes all cogs
for filename in os.listdir('./cogs'):
if filename.endswith('.py') and filename.replace('.py', '') not in FIXED_COGS:
if hasLoaded: bot.unload_extension(f'cogs.{filename.replace(".py","")}')
os.remove(f'./cogs/{filename}')
# Loads all cogs
for filename in os.listdir('./cogs'):
if filename.endswith('.py') and (filename.replace('.py', '') not in FIXED_COGS or not hasLoaded):
bot.load_extension(f'cogs.{filename.replace(".py","")}')
return