-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_mutant.py
56 lines (50 loc) · 2.35 KB
/
bot_mutant.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
import discord, os, psycopg2,random, asyncio, typing
from psycopg2 import sql
from discord.ext import commands
from Emoji import BotEmoji
class Mutations(commands.Cog):
def __init__(self, bot,db_connection):
self.bot = bot
self.db_connection = db_connection
def embed_mutation(self,response):
e = discord.Embed(title="**"+response[0]+"**")
e.add_field(name="Action Order",value=response[1],inline=False)
e.add_field(name="Effect",value=response[2],inline=False)
return e
@commands.command(brief="list your mutations")
async def listm(self,ctx,override=""):
cur = self.db_connection.cursor()
if override=="uv-rays":
cur.execute("select mut_name from mutations;")
else:
cur.execute("select mut_name from p_mutations where user_dis_id='%s'",
[ctx.author.id])
if cur.rowcount:
await ctx.author.send("Your mutations are:")
await ctx.author.send("\n".join(["`"+x[0]+"`" for x in cur.fetchall()]))
@commands.command(hidden=True)
async def givem(self,ctx,user : discord.User,*,mut=None):
cur = self.db_connection.cursor()
if not mut:
cur.execute(
"""SELECT mutations.mut_name from mutations except
SELECT mutations.mut_name from mutations,p_mutations
where mutations.mut_name=p_mutations.mut_name and p_mutations.user_dis_id ='%s'""",
[user.id])
mut = cur.fetchone()[0]
cur.execute("insert into p_mutations VALUES (%s,%s);",
[user.id,mut])
if cur.rowcount:
await user.send(f"_you now have the mutation {mut}_\n list your mutations with `FC_listm` and learn about them with `FC_minfo`")
self.db_connection.commit()
@commands.command(brief="find out information about a mutation")
async def minfo(self,ctx,*,name):
cur = self.db_connection.cursor()
cur.execute("select * from mutations where mut_name=%s;",[name])
column_names = [desc[0] for desc in cur.description]
out = cur.fetchone()
if out:
mut = await ctx.send(embed=self.embed_mutation(out))
await mut.add_reaction(BotEmoji.EXIT_EMOJI.value)
else:
await ctx.send("**MUTATIONS ARE TREASONOUS**")