· 4 years ago · Jul 09, 2021, 02:08 PM
1'''
2DOWNLOAD RandomStuff.py library
3CREATE A NEW FILE NAMED database.sqlite
4'''
5
6
7'''
8CODE CREATED BY KAZUMA
9'''
10
11'''
12API BY PGAMERX
13'''
14
15@client.event
16async def on_ready():
17 db = sqlite3.connect('database.sqlite')
18 cursor = db.cursor()
19 cursor.execute('''
20 CREATE TABLE IF NOT EXISTS database(
21 guild_id TEXT,
22 channel_id TEXT
23 )
24 ''')
25 db.commit()
26
27
28
29
30ai_chat_servers = {}
31
32api_key = 'YOUR API KEY'
33
34'''
35PLEASE GET YOUR OWN API KEY FROM https://api-info.pgamerx.com/register
36'''
37
38rs = randomstuff.AsyncClient(api_key= api_key)
39
40
41@client.command()
42async def configure(ctx, channel: discord.TextChannel):
43 db = sqlite3.connect('database.sqlite')
44 cursor = db.cursor()
45
46 cursor.execute("SELECT channel_id FROM database WHERE guild_id = ?", (ctx.guild.id,))
47 result = cursor.fetchone()
48 if result is None:
49 sql = ("INSERT INTO database(guild_id, channel_id) VALUES(?,?)")
50 val = (ctx.guild.id, channel.id)
51 elif result is not None:
52 sql = ("UPDATE database SET channel_id = ? WHERE guild_id = ?")
53 val = (channel.id, ctx.guild.id)
54 cursor.execute(sql,val)
55 db.commit()
56 cursor.close()
57 db.close()
58
59 #server_id = ctx.guild.id
60 #ai_chat_servers[server_id] = channel.id
61 await ctx.send(f'AI Chat is now set to {channel}')
62
63
64@client.event
65async def on_message(message):
66
67 await client.process_commands(message)
68
69 if client.user == message.author:
70 return
71
72 if message.content is None:
73 return
74
75 db = sqlite3.connect('database.sqlite')
76 cursor = db.cursor()
77 cursor.execute("SELECT channel_id FROM database WHERE guild_id = ?", (message.guild.id,))
78 result = cursor.fetchone()
79 if result is None:
80 return
81
82 if message.channel.id == int(result[0]):
83 try:
84 response = await rs.get_ai_response(message=message.content)
85 async with message.channel.typing():
86 #asyncio.sleep(2)
87 await message.reply(response.message)
88
89
90 except:
91 random_shit = ['Oh', 'Well, I got it', 'Hmmmmmm', 'Hey', 'Umm Lemme Think', 'Um', 'Thats not very nice of you', 'Youre so sus', 'Alright', 'Hmm K', 'Okkk']
92 random_response = random.choice(random_shit)
93 async with message.channel.typing():
94 await message.reply(random_response)