-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
108 lines (85 loc) · 2.68 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
import os
import discord
import requests
import json
import random
import text2emotion as te
from replit import db
from keep_alive import keep_alive
client = discord.Client()
starter_motivation = [
"Cheer Up!!",
"You can and You will.",
"You are great.",
"Everything will be solved."
]
starter_good = [
"Thats Cool!",
"Keep going.",
"Much Appreciated."
]
if ("responding" not in db.keys()):
db['responding'] = True
def get_quote():
response = requests.get("https://zenquotes.io/api/random")
json_data = json.loads(response.text)
quote = json_data[0]['q'] + "\n- " + json_data[0]['a']
return (quote)
def update_motivations(motivating_message):
if ("motivations" in db.keys()):
motivations = db['motivations']
motivations.append(motivating_message)
db['motivations'] = motivations
else:
db['motivations'] = [motivating_message]
def delete_motivation(index):
motivations = db['motivations']
if (len(motivations) > index):
del motivations[index]
db['motivations'] = motivations
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
scores = te.get_emotion(msg)
if msg.startswith('!inspire'):
quote = get_quote()
await message.channel.send(quote)
if db['responding']:
options = starter_motivation
if ('motivations' in db.keys()):
options = options + list(db['motivations'])
if ((scores['Sad'] > 0.5) or (scores['Angry'] > 0.5) or (scores['Fear'] > 0.5)):
await message.channel.send(random.choice(options))
if ((scores['Happy'] > 0.5) or (scores['Surprise'] > 0.5)):
await message.channel.send(random.choice(starter_good))
if (msg.startswith('!new ')):
motivating_message = msg.split('!new', 1)[1]
update_motivations(motivating_message)
await message.channel.send('New Motivating Message added.')
if (msg.startswith('!del')):
motivations = []
if ('motivations' in db.keys()):
index = int(msg.split('!del', 1)[1])
delete_motivation(index)
motivations = db['motivations']
await message.channel.send(motivations)
if msg.startswith('!list'):
motivations = []
if ('motivations' in db.keys()):
motivations = db['motivations']
await message.channel.send(motivations)
if msg.startswith('!responding'):
value = msg.split('!responding', 1)[1]
if (value.lower() == True):
db['responding'] = True
await message.channel.send('Responding is On.')
else:
db['responding'] = True
await message.channel.send('Responding is Off.')
keep_alive()
client.run(os.environ['TOKEN'])