forked from bnleft/HackCWRU-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
301 lines (241 loc) 路 9.8 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
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
import discord
from discord.ext import commands, tasks
import requests
import os
import io
import random
from dotenv import load_dotenv
from jokeapi import Jokes
import dbms
import functions
from datetime import datetime, timedelta
import asyncio
from PIL import Image, ImageDraw, ImageSequence
load_dotenv()
token = os.getenv('TOKEN')
prefix = os.getenv('PREFIX')
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix = prefix, intents=intents)
##########
# events #
##########
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
dbms.userConnect()
@client.event
async def on_message(message):
await client.process_commands(message)
if functions.checkUserExist(message.author.id):
functions.checkWordExist(message.author.id, message.content)
# Check mood of user and send DM accordingly
user = message.author
if not dbms.userSearch(user.id):
pass
elif dbms.userSearch(user.id)[0][2] > 15:
# Positive message
await send_user_status_update(user.id)
elif dbms.userSearch(user.id)[0][3] > 15:
# Negative message
await send_user_status_update(user.id, positive=False)
@client.event
async def on_member_join(member):
await member.send(f"Hello there {member}! I'm SenPy. I'm your potential guide to happiness and a savior from sadness. If you'd like me to monitor your happiness levels, reply with a 'Yes'. Otherwise, reply with a 'No'.")
msg = await client.wait_for('message', check=lambda m: m.author == member and m.channel == member.dm_channel, timeout=60)
if (msg.content.strip() == "Yes"):
dbms.userInsert(member.id, 0, 0)
await member.send("Your messages will now be monitored!")
###################
# therapy command #
###################
location_question = "Well hello there! I can help you seek therapy around your physical location. May I please know your city and state? **Format:** $location Cleveland, OH"
@client.command('therapy')
async def therapy_command(ctx):
await ctx.author.send(location_question)
msg = await client.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == ctx.author.dm_channel, timeout=60)
user_location_response = msg.content
city, state = msg.content.split(", ")
therapists_url = f"https://www.goodtherapy.org/therapists/{state}/{city}"
await ctx.author.send("Here are some therapists in your area: \n" + therapists_url)
#################
# canny command #
#################
file_path = './assets/canny.gif'
canny_gif = Image.open(file_path)
@client.command('canny')
async def canny_command(ctx):
url = ctx.author.avatar_url
pfp_path = './assets/pfp.png'
pfp = Image.open(requests.get(url, stream=True).raw)
pfp.save(pfp_path, 'PNG')
with open(pfp_path, 'rb') as f:
pic = discord.File(f)
await ctx.send(file=pic)
with open(file_path, 'rb') as f:
gif = discord.File(f)
await ctx.send(file=gif)
#################
# quote command #
#################
@client.command('quote')
async def quote_command(ctx):
response = requests.get("https://type.fit/api/quotes")
quote_arr = response.json()
rand = random.randint(0, len(quote_arr))
quote = quote_arr[rand]['text'] + " \n- " + quote_arr[rand]['author']
await ctx.send(quote)
####################
# hotlines command #
####################
hotline_names = ["SAMSHA National Helpline",
"NAMI",
"National Suicide Prevention Hotline",
"Boys Town Hotline"]
hotline_links = ["https://www.samhsa.gov/find-help/national-helpline",
"https://www.nami.org/help",
"https://suicidepreventionlifeline.org/",
"https://www.boystown.org/hotline/Pages/default.aspx"]
hotline_numbers = ["1-800-662-4357",
"1-800-950-6264",
"1-800-273-8255",
"1-800-448-3000"]
@client.command('hotlines')
async def hotlines_command(ctx):
embed = discord.Embed()
title = "Hotlines"
desc = ""
color = discord.Color.blue();
for i in range(len(hotline_names)):
desc += hotline_numbers[i] + " -- "
desc += "[" + hotline_names[i] + "]"
desc += "(" + hotline_links[i] + ")"
desc += "\n"
embed.title = title
embed.description = desc
embed.color = color
await ctx.send(embed=embed)
#################
# Links command #
#################
embed_titles = ["Psych Central",
"Headspace",
"Therapy Tribe",
"Calm Sage",
"Doxy"]
embed_urls = ["https://psychcentral.com/",
"https://www.headspace.com/",
"https://support.therapytribe.com/",
"https://www.calmsage.com/",
"https://www.doxy.me/"]
embed_descriptions = ["Psych Central is one of the oldest websites about mental health. The award winning website has been around ever since 1995 and has touched the lives of many. As is quite evident from the name the blog keenly focuses on the psych of a person.",
"If you are finding it hard to focus on your life-goals all because you are stressed, then you should definitely check Headspace out. It contains hundreds of articles and blogs about mental health.",
"Therapy Tribe takes peer-to-peer mental health support to the next level. Apart from a range of resources, it offers dedicated domains or Tribes for many different issues.",
"If you like the idea of sharing your personal stories and discovering people with the same experiences, try out Calm Sage. The website is more educational than a place to connect, but it does welcome guest posts about mental health triumphs.",
"doxy.me is a free, secure, simple online platform for telemedicine. Telemedicine will change the world by making it easier and more affordable for healthcare providers to care for their patients anywhere, including rural and underserved areas. We believe everyone should have access to care through telemedicine."]
embed_colors = [0xFFA500,
0xFFFFFF,
0xBF40BF,
0xFFFF00,
0xADD8E6]
@client.command('links')
async def links_command(ctx):
for i in range (5):
messageLinks = discord.Embed(title=embed_titles[i],url=embed_urls[i],description = embed_descriptions[i], color = embed_colors[i])
await ctx.send(embed = messageLinks)
################
# joke command #
################
@client.command('joke')
async def joke_command(ctx):
j = await Jokes()
joke = await j.get_joke(blacklist=['nsfw', 'racist', 'sexist', 'religious'])
joke_message = ""
if joke["type"] == "single":
joke_message += joke["joke"]
else:
joke_message += joke["setup"]
joke_message += joke["delivery"]
await ctx.send(joke_message)
################
# meme command #
################
@client.command('meme')
async def meme_command(ctx):
base_url = "https://meme-api.herokuapp.com/gimme"
r = requests.get(base_url)
r = r.json()
image_url = r["url"]
await ctx.send(image_url)
@tasks.loop(hours=24)
async def command_quote():
channel = client.get_channel(954837807187247255)
r = requests.get("https://zenquotes.io/api/random").json()
quote = r[0]["q"]
author = r[0]["a"]
await channel.send(quote + "\n --" + author)
#####################
# debugging command #
#####################
@client.command('printUsers')
async def print_command(ctx):
for i in dbms.userView():
await ctx.send(i)
@client.command('searchUser')
async def search_command(ctx, discordId):
await ctx.send(functions.checkUserExist(discordId))
@command_quote.before_loop
async def before():
now = datetime.now()
target = datetime(*now.timetuple()[0:3], hour=16, minute=11)
if target < now:
target += datetime.timedelta(days=1)
diff = target - now
await asyncio.sleep(diff.seconds)
await client.wait_until_ready()
print("Finished waiting")
################
# help command #
################
@client.command()
async def helpMee(ctx):
senpy_cmd_dictionary = {
'help': 'Current Commmand.',
'quote': 'Pings you with happy & motivational quotes.',
'hotlines': 'Not feeling it? Emergency hotlines are always there to help you!',
'links': 'Seek online mental help using the mental health websites we recommend.',
'therapy': 'I will personally help you with seeking mental therapy around you.',
'joke': 'You know what this does haha! 馃槉',
'memes': 'You know what this does also 馃槣',
'canny': 'Become Mr. cannyble'
}
senpy_cmds = ['help',
'quote'
'hotlines',
'links',
'therapy',
'joke',
'memes',
'canny']
senpy_description = ['Current Commmand.',
'Pings you with happy & motivational quotes.',
'Not feeling it? Emergency hotlines are always there to help you!',
'Seek online mental help using the mental health websites we recommend.',
'I will personally help you with seeking mental therapy around you.',
'You know what this does haha! 馃槉',
'You know what this does also 馃槣',
'Become Mr. cannyble']
for i in range (len(senpy_cmds)):
messageCommands = discord.Embed(title="!"+senpy_cmds[i],url="",description=senpy_description[i],color= 0xFFFFFF)
await ctx.send(embed = messageCommands)
async def send_user_status_update(discordId, positive=True):
user = client.get_user(discordId)
if positive:
# Positive message
message = "Congratulations! Your SenPy score has reached 15."
else:
# Negative message
message = "Oh no! Your SenPy score has dropped below -15."
await user.send(message)
command_quote.start()
client.run(token)