insert more slash commands like roll and gmroll

This commit is contained in:
Aaron Riedel 2022-01-23 22:59:28 +01:00
parent ec7bdc6b20
commit 095abc6fbd

98
bot.py
View file

@ -8,6 +8,7 @@ from os import system
from os import environ from os import environ
from discord.ext import commands from discord.ext import commands
from discord.commands import Option from discord.commands import Option
from discord.commands import permissions
def left(s, amount): def left(s, amount):
return s[:amount] return s[:amount]
@ -23,25 +24,29 @@ prefix = os.environ['PREFIX']
bot = commands.Bot(command_prefix=prefix) bot = commands.Bot(command_prefix=prefix)
client = discord.Client() client = discord.Client()
admin_role=261603488331595776
member_role=261603747711418371
gm_role=511893805956595722
def admin(ctx): 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 return True
def member(ctx): 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 return True
def is_admin(): def is_admin():
async def predicate(ctx): 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 True
return commands.check(predicate) return commands.check(predicate)
def is_member(): def is_member():
async def predicate(ctx): 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 True
return commands.check(predicate) return commands.check(predicate)
def is_gm(): def is_gm():
async def predicate(ctx): 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 True
return commands.check(predicate) return commands.check(predicate)
@ -77,17 +82,34 @@ class Confirm(discord.ui.View):
self.value = False self.value = False
self.stop() self.stop()
class vote_view(discord.ui.View):
@bot.slash_command(guild_ids=[261575556708040705]) # create a slash command for the supplied guilds def __init__(self):
async def hello(ctx): super().__init__()
"""Say hello to the bot""" self.value = None
await ctx.respond(content="Hallo %s" % ctx.author.display_name, ephemeral=True) @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]) @bot.slash_command(guild_ids=[261575556708040705])
@permissions.has_role(member_role)
async def roll(ctx, 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 rollt = 0
rolle = " " rolle = " "
roll = dice.lower() roll = dice.lower()
@ -113,7 +135,51 @@ async def roll(ctx,
rolltotal = rolle + "\n" + rolltotal rolltotal = rolle + "\n" + rolltotal
rolle = "" rolle = ""
em = discord.Embed(title=rolle, description=rolltotal, colour=0x009933) 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="<Text>", hidden=True) @bot.command(help="Wirft den gleichen Text zurück.", usage="<Text>", hidden=True)
@is_admin() @is_admin()
@ -151,7 +217,7 @@ async def survey(ctx, *, arg):
desc = desc + emojinumbers[z] + " - " + y + "\n" desc = desc + emojinumbers[z] + " - " + y + "\n"
z = z + 1 z = z + 1
em = discord.Embed(title=question, description=desc, colour=0x00E0FF) 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) ask_msg = await ctx.send(content="||@here||",embed=em)
a = 0 a = 0
for x in emojinumbers: for x in emojinumbers:
@ -175,7 +241,7 @@ async def surveyedit(ctx, *, arg):
desc = desc + emojinumbers[z] + " - " + y + "\n" desc = desc + emojinumbers[z] + " - " + y + "\n"
z = z + 1 z = z + 1
em = discord.Embed(title=question, description=desc, colour=0x00E0FF) 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))) survey_msg = await ctx.channel.fetch_message((int(survey_id)))
await survey_msg.edit(embed=em) await survey_msg.edit(embed=em)
@ -184,7 +250,7 @@ async def surveyedit(ctx, *, arg):
async def vote(ctx, *, arg): async def vote(ctx, *, arg):
await ctx.message.delete() await ctx.message.delete()
em = discord.Embed(description=arg, colour=0x00E0FF) 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) ask_msg = await ctx.send(content="||@here||",embed=em)
for x in ["", "", ""]: for x in ["", "", ""]:
await ask_msg.add_reaction(x) await ask_msg.add_reaction(x)