-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (39 loc) · 1.73 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
import discord
from data_base import data_base
from dropdown import DropDown
import answer_button
from discord.ui import View
bot = discord.Bot()
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
@bot.slash_command(guild_ids=[914264804171079702], description="Create a new card")
async def new(ctx: discord.ApplicationContext, front: str, back: str):
if data_base.add(ctx.author.id, front, back):
await ctx.respond("Card created")
else:
await ctx.respond("A card with that front already exists")
@bot.slash_command(guild_ids=[914264804171079702], description="Start a Memorum session")
async def ask(ctx):
await answer_button.ask(ctx)
@bot.slash_command(guild_ids=[914264804171079702], description="Select cards to delete them")
async def delete(ctx):
if data_base.isEmpty(ctx.author.id):
return await ctx.respond("No cards yet")
view = View(DropDown(ctx.author.id))
await ctx.respond("Question log:", view=view)
@bot.slash_command(guild_ids=[914264804171079702], description="Get information about your sessions")
async def info(ctx):
info = data_base.info(ctx.author.id)
await ctx.respond("Number of Cards: " + str(info["number_cards"]) +
"\nNumber of cards received: " + str(info["cards_received"]) + "\n")
@bot.slash_command(guild_ids=[914264804171079702], description="Set all Cards fields to their default. Preserve \"front\" and \"back\" fields")
async def reset(ctx):
data_base.reset(ctx.author.id)
await ctx.respond("Information has been reset to its original values")
def read_token() -> str:
with open("token.txt", "r") as f:
lines = f.readlines()
return lines[0].strip()
token = read_token()
bot.run(token)