Compare commits

...

4 Commits

Author SHA1 Message Date
a914b17ade Added fix for leaved users 2024-05-19 20:56:38 +02:00
868fb4634a Added fix for leaved users 2024-05-19 20:48:31 +02:00
2dc8688937 Changed color 2023-12-26 13:50:32 +01:00
c6c1748f3e Added refresh command 2023-12-26 13:42:53 +01:00

28
main.py
View File

@@ -45,7 +45,7 @@ async def on_ready():
def create_embed(guild): def create_embed(guild):
embed = discord.Embed( embed = discord.Embed(
title="Schimpfwortkasse", title="Schimpfwortkasse",
color=discord.Colour.blurple(), color=discord.Colour.magenta(),
) )
with DBConnection() as cur: with DBConnection() as cur:
@@ -65,7 +65,12 @@ def create_embed(guild):
if precount != 0: if precount != 0:
description = description + "**Vorheriger Stand:** " + str(precount) + " Euro\n" description = description + "**Vorheriger Stand:** " + str(precount) + " Euro\n"
for member in members: for member in members:
description = description + "**" + guild.get_member(member[0]).display_name + "**: " + str(member[1]) + " Euro \n"
if hasattr(guild.get_member(member[0]), "display_name"):
name = guild.get_member(member[0]).display_name
else:
name = "Unknown User"
description = description + "**" + name + "**: " + str(member[1]) + " Euro \n"
embed.add_field(name="Bestenliste:", value=description) embed.add_field(name="Bestenliste:", value=description)
return embed return embed
@@ -77,14 +82,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 +105,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):