-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (66 loc) · 1.83 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
import discord
import os
import json
import sqlite3
from discord.ext import commands
from prsaw import RandomStuff
client= commands.Bot(command_prefix="!!", case_insensitive=True)
client.remove_command("help")
rs= RandomStuff(async_mode=True)
conn= sqlite3.connect("dbs/main.db")
with open("config.json", "r") as f:
config= json.load(f)
f.close()
TOKEN= config['token']
extensions= [
"commands",
]
@client.event
async def on_ready():
for extension in extensions:
client.load_extension(f"cogs.{extension}")
if os.name == 'nt':
os.system("cls")
else:
os.system('clear')
print("[ Discord ChatBot ]\n")
print(f"\nCurrently Logged in as: {client.user.name}")
print(f"ID: {client.user.id}")
@client.event
async def on_message(message):
if message.author == client.user:
return
else:
if message.content.lower().startswith('!!'):
await client.process_commands(message)
cur= conn.cursor()
guildID= str(message.guild.id)
r= cur.execute("SELECT * FROM main WHERE guild_id = '"+guildID+"'")
row = None
for row in r:
...
if row[2] == "0":
return
if row == None:
return
elif row != None:
if message.channel.id == int(row[1]):
async with message.channel.typing():
try:
msg = message.content
if message.mentions != []:
for i in message.mentions:
msg = msg.replace(f'<@!{i.id}>', i.name)
response= await rs.get_ai_response(msg)
except json.decoder.JSONDecodeError:
await asyncio.sleep(3)
response= await rs.get_ai_response(msg)
await message.channel.send(response)
else:
return
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f":warning: This command is currently on cooldown. Try again in {round(error.retry_after, 2)} seconds.")
print(error)
client.run(TOKEN)