From 86fd0048c1b2cfbedc87d9f555c72494a56f16d9 Mon Sep 17 00:00:00 2001 From: Aaron Riedel Date: Sun, 23 Jan 2022 06:05:18 +0100 Subject: [PATCH 1/5] change libary to py-cord --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 503dba9..7df7302 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -discord.py \ No newline at end of file +py-cord \ No newline at end of file From ec7bdc6b206152d39e9def7f847e6356712bf926 Mon Sep 17 00:00:00 2001 From: Aaron Riedel Date: Sun, 23 Jan 2022 19:41:22 +0100 Subject: [PATCH 2/5] added Slash commands --- bot.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 35cbdec..73d07b2 100644 --- a/bot.py +++ b/bot.py @@ -7,6 +7,7 @@ import os from os import system from os import environ from discord.ext import commands +from discord.commands import Option def left(s, amount): return s[:amount] @@ -59,6 +60,61 @@ async def on_command_error(ctx, error): async def on_ready(): print("Bot ready on Version %s..." % discord.__version__) +class Confirm(discord.ui.View): + def __init__(self): + super().__init__() + self.value = None + @discord.ui.button(label="Confirm", style=discord.ButtonStyle.green) + async def confirm( + self, button: discord.ui.Button, interaction: discord.Interaction + ): + await interaction.response.send_message("Bestätigt", ephemeral=True, delete_after=5.0) + self.value = True + self.stop() + @discord.ui.button(label="Cancel", style=discord.ButtonStyle.grey) + async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction): + await interaction.response.send_message("Abgebrochen", ephemeral=True, delete_after=5.0) + self.value = False + self.stop() + + +@bot.slash_command(guild_ids=[261575556708040705]) # create a slash command for the supplied guilds +async def hello(ctx): + """Say hello to the bot""" + await ctx.respond(content="Hallo %s" % ctx.author.display_name, ephemeral=True) + +@bot.slash_command(guild_ids=[261575556708040705]) +async def roll(ctx, + dice: Option(str, "Würfel die du werfen willst. z.B. 4W20"), + ): + await ctx.defer() + rollt = 0 + rolle = " " + roll = dice.lower() + if "d" in roll: + rolls = "d" + if "w" in roll: + rolls = "w" + rollc = roll.split(rolls)[0] + if rollc == "": + rollc = 1 + else: + rollc = int(rollc) + rolld = int(roll.split(rolls)[1]) + for x in range(rollc): + rollo = random.randint(1, rolld) + rollt = rollt + rollo + rolle = rolle + " :game_die: " + str(rollo) + " " + if rollc > 1: + rolltotal = "Total: " + str(rollt) + else: + rolltotal = "" + if rollc > 12: + rolltotal = rolle + "\n" + rolltotal + rolle = "" + em = discord.Embed(title=rolle, description=rolltotal, colour=0x009933) + await ctx.respond(embed=em) + @bot.command(help="Wirft den gleichen Text zurück.", usage="", hidden=True) @is_admin() async def test(ctx, arg): @@ -284,18 +340,19 @@ async def love(ctx, *, arg): async def prune(ctx): await ctx.message.delete() count = await ctx.guild.estimate_pruned_members(days=30) - question = await ctx.channel.send("Sollen wirklich {} Leichen gekickt werden?".format(count)) - def check(reaction, user): - return user == ctx.author and str(reaction.emoji) == "✅" - await question.add_reaction("✅") - try: - reaction, user = await bot.wait_for("reaction_add", timeout=60.0, check=check) - except asyncio.TimeoutError: + view = Confirm() + question = await ctx.send("Sollen wirklich {} Leichen gekickt werden?".format(count), view=view) + await view.wait() + if view.value is None: await question.delete() - else: + await ctx.send(content="Zeit ausgelaufen", delete_after=5.0) + elif view.value: await question.delete() deleted = await ctx.guild.prune_members(days=30) await ctx.send(content='Ich habe {} Leichen beseitigt.'.format(deleted), delete_after=5.0) + else: + await question.delete() + @bot.command(help="Rolle einen oder mehrere Würfel", usage="W (z.B. %sroll W20 oder %sroll 10W6)" % (prefix, prefix)) @is_member() From 095abc6fbd42bee3c4d21573d03fe8d89183cef8 Mon Sep 17 00:00:00 2001 From: Aaron Riedel Date: Sun, 23 Jan 2022 22:59:28 +0100 Subject: [PATCH 3/5] insert more slash commands like roll and gmroll --- bot.py | 98 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 16 deletions(-) diff --git a/bot.py b/bot.py index 73d07b2..f41ada5 100644 --- a/bot.py +++ b/bot.py @@ -8,6 +8,7 @@ from os import system from os import environ from discord.ext import commands from discord.commands import Option +from discord.commands import permissions def left(s, amount): return s[:amount] @@ -23,25 +24,29 @@ prefix = os.environ['PREFIX'] bot = commands.Bot(command_prefix=prefix) client = discord.Client() +admin_role=261603488331595776 +member_role=261603747711418371 +gm_role=511893805956595722 + def admin(ctx): - if ctx.guild.get_role(261603488331595776) in ctx.author.roles: + if ctx.guild.get_role(admin_role) in ctx.author.roles: return True def member(ctx): - if ctx.guild.get_role(261603747711418371) in ctx.author.roles: + if ctx.guild.get_role(member_role) in ctx.author.roles: return True def is_admin(): async def predicate(ctx): - if ctx.guild.get_role(261603488331595776) in ctx.author.roles: + if ctx.guild.get_role(admin_role) in ctx.author.roles: return True return commands.check(predicate) def is_member(): async def predicate(ctx): - if ctx.guild.get_role(261603747711418371) in ctx.author.roles: + if ctx.guild.get_role(member_role) in ctx.author.roles: return True return commands.check(predicate) def is_gm(): async def predicate(ctx): - if ctx.guild.get_role(511893805956595722) in ctx.author.roles: + if ctx.guild.get_role(gm_role) in ctx.author.roles: return True return commands.check(predicate) @@ -77,17 +82,34 @@ class Confirm(discord.ui.View): self.value = False self.stop() - -@bot.slash_command(guild_ids=[261575556708040705]) # create a slash command for the supplied guilds -async def hello(ctx): - """Say hello to the bot""" - await ctx.respond(content="Hallo %s" % ctx.author.display_name, ephemeral=True) +class vote_view(discord.ui.View): + def __init__(self): + super().__init__() + self.value = None + @discord.ui.button(label="Ja", style=discord.ButtonStyle.green) + async def yes( + self, button: discord.ui.Button, interaction: discord.Interaction + ): + await interaction.response.send_message("Bestätigt", ephemeral=True) + self.value = "yes" + self.stop() + @discord.ui.button(label="Vielleicht", style=discord.ButtonStyle.grey) + async def maybe(self, button: discord.ui.Button, interaction: discord.Interaction): + await interaction.response.send_message("Abgebrochen", ephemeral=True) + self.value = "maybe" + self.stop() + @discord.ui.button(label="Nein", style=discord.ButtonStyle.red) + async def no(self, button: discord.ui.Button, interaction: discord.Interaction): + await interaction.response.send_message("Abgebrochen", ephemeral=True) + self.value = "no" + self.stop() @bot.slash_command(guild_ids=[261575556708040705]) +@permissions.has_role(member_role) async def roll(ctx, - dice: Option(str, "Würfel die du werfen willst. z.B. 4W20"), + dice: Option(str, "Würfel den/die du werfen willst. z.B. W20, 3d6", default="W20"), ): - await ctx.defer() + """Rolle einen oder mehrere Würfel""" rollt = 0 rolle = " " roll = dice.lower() @@ -113,7 +135,51 @@ async def roll(ctx, rolltotal = rolle + "\n" + rolltotal rolle = "" em = discord.Embed(title=rolle, description=rolltotal, colour=0x009933) - await ctx.respond(embed=em) + await ctx.response.send_message(embed=em) + +@bot.slash_command(guild_ids=[261575556708040705]) +@permissions.has_role(gm_role) +async def gmroll(ctx, + dice: Option(str, "Würfel den/die du werfen willst. z.B. W20, 3d6", default="W20"), + ): + """Rolle einen oder mehrere Würfel verdeckt""" + rollt = 0 + rolle = " " + roll = dice.lower() + if "d" in roll: + rolls = "d" + if "w" in roll: + rolls = "w" + rollc = roll.split(rolls)[0] + if rollc == "": + rollc = 1 + else: + rollc = int(rollc) + rolld = int(roll.split(rolls)[1]) + for x in range(rollc): + rollo = random.randint(1, rolld) + rollt = rollt + rollo + rolle = rolle + " :game_die: " + str(rollo) + " " + if rollc > 1: + rolltotal = "Total: " + str(rollt) + else: + rolltotal = "" + if rollc > 12: + rolltotal = rolle + "\n" + rolltotal + rolle = "" + em = discord.Embed(title=rolle, description=rolltotal, colour=0x009933) + await ctx.response.send_message(embed=em, ephemeral=True) + +@bot.slash_command(guild_ids=[261575556708040705]) +@permissions.has_role(member_role) +async def vote(ctx, + question: Option(str, "zu stellende Frage"), + ): + """Erstelle eine Abstimmung""" + em = discord.Embed(title=question, colour=0x00E0FF) + em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar.url) + view=vote_view() + await ctx.response.send_message(content="||@here||",embed=em, view=view) @bot.command(help="Wirft den gleichen Text zurück.", usage="", hidden=True) @is_admin() @@ -151,7 +217,7 @@ async def survey(ctx, *, arg): desc = desc + emojinumbers[z] + " - " + y + "\n" z = z + 1 em = discord.Embed(title=question, description=desc, colour=0x00E0FF) - em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar_url) + em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar.url) ask_msg = await ctx.send(content="||@here||",embed=em) a = 0 for x in emojinumbers: @@ -175,7 +241,7 @@ async def surveyedit(ctx, *, arg): desc = desc + emojinumbers[z] + " - " + y + "\n" z = z + 1 em = discord.Embed(title=question, description=desc, colour=0x00E0FF) - em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar_url) + em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar.url) survey_msg = await ctx.channel.fetch_message((int(survey_id))) await survey_msg.edit(embed=em) @@ -184,7 +250,7 @@ async def surveyedit(ctx, *, arg): async def vote(ctx, *, arg): await ctx.message.delete() em = discord.Embed(description=arg, colour=0x00E0FF) - em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar_url) + em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar.url) ask_msg = await ctx.send(content="||@here||",embed=em) for x in ["✅", "❔", "❌"]: await ask_msg.add_reaction(x) From 5978e40e78d030c98407fd9d18693065d58d6dde Mon Sep 17 00:00:00 2001 From: Aaron Riedel Date: Tue, 25 Jan 2022 06:50:06 +0100 Subject: [PATCH 4/5] remove test stuff --- bot.py | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/bot.py b/bot.py index f41ada5..856db28 100644 --- a/bot.py +++ b/bot.py @@ -82,28 +82,6 @@ class Confirm(discord.ui.View): self.value = False self.stop() -class vote_view(discord.ui.View): - def __init__(self): - super().__init__() - self.value = None - @discord.ui.button(label="Ja", style=discord.ButtonStyle.green) - async def yes( - self, button: discord.ui.Button, interaction: discord.Interaction - ): - await interaction.response.send_message("Bestätigt", ephemeral=True) - self.value = "yes" - self.stop() - @discord.ui.button(label="Vielleicht", style=discord.ButtonStyle.grey) - async def maybe(self, button: discord.ui.Button, interaction: discord.Interaction): - await interaction.response.send_message("Abgebrochen", ephemeral=True) - self.value = "maybe" - self.stop() - @discord.ui.button(label="Nein", style=discord.ButtonStyle.red) - async def no(self, button: discord.ui.Button, interaction: discord.Interaction): - await interaction.response.send_message("Abgebrochen", ephemeral=True) - self.value = "no" - self.stop() - @bot.slash_command(guild_ids=[261575556708040705]) @permissions.has_role(member_role) async def roll(ctx, @@ -170,22 +148,6 @@ async def gmroll(ctx, em = discord.Embed(title=rolle, description=rolltotal, colour=0x009933) await ctx.response.send_message(embed=em, ephemeral=True) -@bot.slash_command(guild_ids=[261575556708040705]) -@permissions.has_role(member_role) -async def vote(ctx, - question: Option(str, "zu stellende Frage"), - ): - """Erstelle eine Abstimmung""" - em = discord.Embed(title=question, colour=0x00E0FF) - em.set_author(name=ctx.author.display_name, url=discord.Embed.Empty, icon_url=ctx.author.avatar.url) - view=vote_view() - await ctx.response.send_message(content="||@here||",embed=em, view=view) - -@bot.command(help="Wirft den gleichen Text zurück.", usage="", hidden=True) -@is_admin() -async def test(ctx, arg): - await ctx.send(arg) - @bot.command(help="veraltet", usage="", hidden=True) @is_member() async def yesno(ctx): From c7bd4380afae9b7fc7adc1ef85a601ead7e4c85d Mon Sep 17 00:00:00 2001 From: Aaron Riedel Date: Sat, 29 Jan 2022 07:47:07 +0100 Subject: [PATCH 5/5] use beta 1 of py-cord lib --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7df7302..64ab083 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -py-cord \ No newline at end of file +py-cord==2.0.0b1 \ No newline at end of file