65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
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") |