-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhraseBot.py
More file actions
67 lines (59 loc) · 2.03 KB
/
Copy pathPhraseBot.py
File metadata and controls
67 lines (59 loc) · 2.03 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
#Discord Bot
#Ben Shakow
#with help from https://discordpy.readthedocs.io
import discord
from discord.ext import commands
from STest import STest
#Receive token from hidden file
File = open('tokens.txt','r')
token = File.read()
File.close()
#Bring in our neural network
nn = STest()
#set up file paths / prefixes
prefix = '?'
goodPath = 'good.txt'
badPath = 'bad.txt'
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
#these two are for adding to the bad/good lists
if message.content.startswith(prefix+'good'):
phrase = message.content[6:]
await client.send_message(message.channel, content = 'The phrase "' + phrase + '" is now in the good words list!')
f = open(goodPath, "a")
f.write(phrase + '\n')
f.close()
return
if message.content.startswith(prefix+'recalibrate'):
await client.send_message(message.channel, content = 'Recalibrating the neural network')
exec(open("sentiment_clean.py").read())
File = open('acc','r')
acc = File.read()
File.close()
await client.send_message(message.channel, content = 'Neural Network recalibrated, with an accuracy of '+acc)
return
if message.content.startswith(prefix+'bad'):
phrase = message.content[5:]
await client.send_message(message.channel, content = 'The phrase "' + phrase + '" is now in the bad words list!')
f = open(badPath, "a")
f.write(phrase + '\n')
f.close()
return
#for actually checking a phrase
if message.content.startswith(prefix+'p'):
phrase = message.content[2:]
result = nn.testPhrase(phrase)
msg = 'The phrase "'+ phrase + '" is '
if(result[0]<=.5):
msg += 'bad :('
else:
msg += 'good!'
await client.send_message(message.channel, content = msg)
return
client.run(token.strip())