bot rewritten to use command extension

This commit is contained in:
Jan Metzler 2020-12-13 12:21:10 +01:00
parent 768314d652
commit 13d500adb3
2 changed files with 65 additions and 4 deletions

65
Jan/dbtest command.py Normal file
View File

@ -0,0 +1,65 @@
from discord.ext import commands
import random
class sf_user:
def __init__(self, id, username, dmchannel):
self.id = id
self.name = username
self.channel = dmchannel
self.question = 0
self.category = 0
self.semester = 0
bot = commands.Bot(command_prefix="!")
users = []
@bot.event
async def on_ready():
print("we logged in as {0.user.name}".format(bot))
return
@bot.command()
async def start(ctx):
print("hello")
for i in users:
if i.name == ctx.author:
await ctx.send("User already in database")
return
users.append(sf_user(len(users), ctx.author, await ctx.author.create_dm()))
await users[-1].channel.send("Hello")
return
@bot.command()
async def question(ctx):
current_user = 0
for i in users:
if i.channel == ctx.channel:
current_user = i
if current_user == 0:
await ctx.send("User not in database")
return
q_id = random.randint(0, 10)
users[current_user.id].question = q_id
await current_user.channel.send(q_id)
return
@bot.command()
async def answer(ctx):
current_user = 0
for i in users:
if i.channel == ctx.channel:
current_user = i
if current_user == 0:
await ctx.send("User not in database")
return
await current_user.channel.send(current_user.question)
return
bot.run("Nzg1MTkxODM3OTg3MzczMDg2.X80Q4g.bK_vMhhESanMOA78KxHfmJft2vk")

View File

@ -1,4 +0,0 @@
name; name des nutzers
question; die aktuelle Frage
semester; einstellungen für semester (0 = random)
kategorie; einstellungen für kategorie (0 = random)