-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (41 loc) · 1.6 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
import discord
import os
from dotenv import load_dotenv
from flask import Flask
import pickle
from mongodb import get_warning_count,update_warning_count
load_dotenv()
TOKEN = os.getenv('TOKEN')
app = Flask(__name__)
model = pickle.load(open('/Users/mac/Desktop/detox/model/model.pkl', 'rb'))
vectorizer = pickle.load(open('/Users/mac/Desktop/detox/model/vectorizer.pickle', 'rb'))
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
username = str(message.author)
user_message = str(message.content).lower()
channel = str(message.channel.name)
print(user_message)
if username == self.user:
print("self")
return
msg_df = vectorizer.transform([user_message])
model_prediction = model.predict(msg_df)
# user_warning_count = await get_warning_count(username)
# print(user_warning_count)
if model_prediction[0] == 1:
# if user_warning_count == 9:
# await update_warning_count(username, 1, 0)
# await message.channel.send(f'Warning!!!!! Please user appropriate language, {10-user_warning_count} until '
# f'timeout')
await message.channel.send('Warning!!!!! Please user appropriate language')
return
if user_message == 'hi':
await message.channel.send('Hello')
return
return
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run(TOKEN)