Added refresh command
This commit is contained in:
19
main.py
19
main.py
@@ -77,14 +77,19 @@ class CounterView(discord.ui.View):
|
||||
@discord.ui.button(label="+1", custom_id="count_plus_one", style=discord.ButtonStyle.primary)
|
||||
async def button_callback(self, button, interaction):
|
||||
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, ))
|
||||
channel = interaction.channel
|
||||
message = await channel.fetch_message(int(message_id))
|
||||
await message.edit(embed=create_embed(interaction.guild), view=CounterView())
|
||||
await updatemessage(interaction.guild)
|
||||
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.")
|
||||
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,))
|
||||
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.")
|
||||
async def reset_counter(ctx):
|
||||
|
||||
Reference in New Issue
Block a user