-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
113 lines (62 loc) · 2.29 KB
/
Copy pathmain.py
File metadata and controls
113 lines (62 loc) · 2.29 KB
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
import discord
import json
import sentiment
client = None
def handle_response(message) -> str:
botID = client.user.id
new_message = message.lower().replace(f'<@{botID}>','').strip()
if new_message == 'hello':
return 'Hey there!'
if new_message == 'hi':
return 'meow'
if new_message == '!help':
return 'This is a help message.'
# Joy/Surprise/Neutral/Fear/Disgust/Sadness/Anger
# :heart_eyes_cat: :scream_cat: :crying_cat_face: :pouting_cat: :smiley_cat:
result = sentiment.perform_sentiment_analysis(new_message).lower()
if result == 'joy':
return 'meow :heart_eyes_cat:'
elif result == 'neutral':
return 'meow :smiley_cat:'
elif result in ['surprise', 'fear']:
return 'meow :scream_cat:'
elif result in ['disgust', 'anger']:
return 'meow :pouting_cat:'
elif result == 'sadness':
return 'meow :crying_cat_face:'
return 'Amog'
async def send_message(message, user_message):
try:
response = handle_response(user_message)
if response != None:
await message.channel.send(response)
except Exception as e:
print(e)
def run_discord_bot():
# API Token Security
with open('api_tokens.json') as f:
data = json.load(f)
TOKEN = data["DISC_API_TOKEN"]
intents = discord.Intents.default() # This sets up the default intents
intents.message_content = True # Enable the Message Content intent
global client
client = discord.Client(intents=intents)
@client.event
async def on_ready():
#print(f'{client.user} is now running!')
print('Irthe h wra na xysw')
@client.event
async def on_message(message):
self = client.user
channel = message.channel
isDM:bool = isinstance(channel, discord.channel.DMChannel)
if message.author == self or (self not in message.mentions and not isDM):
return
username = str(message.author)
user_message = str(message.content)
channel = str(message.channel)
print(f"{username} said: '{user_message}' ({channel})")
await send_message(message, user_message)
client.run(TOKEN)
if __name__ == '__main__':
run_discord_bot()