diff --git a/.gitignore b/.gitignore index 5d381cc..810ac04 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ __pycache__/ *.py[cod] *$py.class +# Gesbod data files +guild_data/ +gesbod_token.txt + # C extensions *.so diff --git a/gesmain.py b/gesmain.py index ea6e899..a7f2758 100644 --- a/gesmain.py +++ b/gesmain.py @@ -1,20 +1,61 @@ -import discord +import discord, csv, os from discord import app_commands from discord.ext import commands bot = commands.Bot(command_prefix="&", intents = discord.Intents.all()) +# +# +# + +async def zapis_info_hadanka(guild_id, aktivni, zadavetel_id, fraze, zkratka): + with open(f"guild_data/guild_{guild_id}.csv", 'w', newline='') as csvfile: + fieldnames = ['aktivni', 'zadavatel_id', 'fraze', 'zkratka'] + writer = csv.DictWriter(csvfile, fieldnames=fieldnames) + writer.writeheader() + writer.writerow({'zadavatel_id': zadavetel_id, 'fraze': fraze, 'zkratka': zkratka}) + +async def precti(guild_id, klic): + with open(f'guild_data/guild_{guild_id}.csv', newline='') as csvfile: + reader = csv.DictReader(csvfile) + for row in reader: + return str(row[str(klic)]) +# +# +# + @bot.event async def on_ready(): - print(f"Bot is up and ready, logged in as: {bot.user}") + print(f"[ONREADY] logged in as: {bot.user}") try: synced = await bot.tree.sync() - print(f"synced {len(synced)} command(s)") + print(f"[ONREADY] synced {len(synced)} command(s)") except Exception as e: print(e) -@bot.tree.command(name="helou") -async def helou(interaction: discord.Interaction): - await interaction.response.send_message(f"HAAAJ {interaction.user.mention}! This is a slash command!!!", ephemeral=True) +# +# +# -bot.run("MTIyNzMwMTk2MTc1ODQwODg5Ng.GTcFey.nlNOCHGYQ1F7imc3MbsMj34_BaWfLR7uGH3OcY") \ No newline at end of file +#zadat hadanku serveru +@bot.tree.command(name="makeriddle") +@app_commands.describe(riddle = "few words from which I will make abbreviation for others to guess") #parametr commandu +async def makeriddle(interaction: discord.Interaction, riddle: str): + guildid = interaction.guild_id + if await precti(guildid, 'aktivni') == "ne" or os.path.exists(f'guild_data/guild_{guildid}.csv') == False: + zkratka = "".join(list(w[0].upper() for w in riddle.split(' '))) + await zapis_info_hadanka(guildid, "ano", interaction.user.id, riddle, zkratka) + + await interaction.response.send_message(f"you have set the riddle to: **{riddle}**, you can end the guessing using */end*", ephemeral=True) + print(f"[MAKERIDDLE] in guild {guildid} user {interaction.user.id} set riddle to: {riddle}") + + await interaction.channel.send(f"{interaction.user.display_name} has set a new abbreviation to solve: **{zkratka}**!") + else: + pzkratka = await precti(guildid, 'zkratka') + await interaction.response.send_message(f"Abbreviation already set ({pzkratka})", ephemeral=True) +# +# +# + +TOKEN = open("gesbod_token.txt", 'r').read() +bot.run(TOKEN)