Added refresh command

This commit is contained in:
2023-12-26 13:42:53 +01:00
parent d90e53a9cb
commit c6c1748f3e

19
main.py
View File

@@ -77,14 +77,19 @@ class CounterView(discord.ui.View):
@discord.ui.button(label="+1", custom_id="count_plus_one", style=discord.ButtonStyle.primary) @discord.ui.button(label="+1", custom_id="count_plus_one", style=discord.ButtonStyle.primary)
async def button_callback(self, button, interaction): async def button_callback(self, button, interaction):
with DBConnection() as cur: with DBConnection() as cur:
cur.execute("SELECT value from settings WHERE name='message_id'")
message_id = cur.fetchone()[0]
cur.execute("INSERT INTO member (user_id, count) VALUES (?, 1) ON DUPLICATE KEY UPDATE count=count + 1", (interaction.user.id, )) cur.execute("INSERT INTO member (user_id, count) VALUES (?, 1) ON DUPLICATE KEY UPDATE count=count + 1", (interaction.user.id, ))
channel = interaction.channel await updatemessage(interaction.guild)
message = await channel.fetch_message(int(message_id))
await message.edit(embed=create_embed(interaction.guild), view=CounterView())
await interaction.response.send_message("Ab ins Sparschwein damit!", ephemeral=True) await interaction.response.send_message("Ab ins Sparschwein damit!", ephemeral=True)
async def updatemessage(guild):
with DBConnection() as cur:
cur.execute("SELECT value from settings WHERE name='message_id'")
message_id = cur.fetchone()[0]
cur.execute("SELECT value from settings WHERE name='channel_id'")
channelid = cur.fetchone()[0]
channel = await guild.fetch_channel(int(channelid))
message = await channel.fetch_message(int(message_id))
await message.edit(embed=create_embed(guild), view=CounterView())
@bot.slash_command(name="set_channel", description="Setze den Channel, in dem der Zähler erstellt wird.") @bot.slash_command(name="set_channel", description="Setze den Channel, in dem der Zähler erstellt wird.")
async def set_channel(ctx): async def set_channel(ctx):
@@ -95,6 +100,10 @@ async def set_channel(ctx):
cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_id'", (message.id,)) cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_id'", (message.id,))
await ctx.respond(content="Done", ephemeral=True) await ctx.respond(content="Done", ephemeral=True)
@bot.slash_command(name="update", description="Aktualisiere die Nachricht")
async def set_channel(ctx):
await updatemessage(ctx.guild)
await ctx.respond(content="Done", ephemeral=True)
@bot.slash_command(name="reset_counter", description="Setze den Zähler auf Null.") @bot.slash_command(name="reset_counter", description="Setze den Zähler auf Null.")
async def reset_counter(ctx): async def reset_counter(ctx):