From 3861f20e1fdafe9a534634afa68d22cbd07051cf Mon Sep 17 00:00:00 2001 From: phixxy Date: Fri, 19 Jan 2024 17:57:41 -0800 Subject: [PATCH] removed poll and roll and put them in their own extension --- plugins/roll_poll.py | 52 +++++++++++++++++++++++++++++++++++++++++++ sparkytron3000.py | 53 +++++--------------------------------------- 2 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 plugins/roll_poll.py diff --git a/plugins/roll_poll.py b/plugins/roll_poll.py new file mode 100644 index 0000000..87a75d5 --- /dev/null +++ b/plugins/roll_poll.py @@ -0,0 +1,52 @@ +import random +import discord +from discord.ext import commands + +@commands.command( + description="Poll", + help='Create a poll with up to 9 options. Usage: !poll "Put question here" "option 1" "option 2"', + brief="Enable or disable bot reactions" + ) +async def poll(ctx, question, *options: str): + if len(options) > 9: + await ctx.send("Error: You cannot have more than 9 options") + return + + embed = discord.Embed(title=question, colour=discord.Colour(0x283593)) + for i, option in enumerate(options): + embed.add_field(name=f"Option {i+1}", value=option, inline=False) + + message = await ctx.send(embed=embed) + numbers = {0: "\u0030\ufe0f\u20e3", 1: "\u0031\ufe0f\u20e3", 2: "\u0032\ufe0f\u20e3", 3: "\u0033\ufe0f\u20e3", 4: "\u0034\ufe0f\u20e3", 5: "\u0035\ufe0f\u20e3", 6: "\u0036\ufe0f\u20e3", 7: "\u0037\ufe0f\u20e3", 8: "\u0038\ufe0f\u20e3", 9: "\u0039\ufe0f\u20e3"} + for i in range(len(options)): + await message.add_reaction(numbers.get(i+1)) + +@commands.command( + description="Roll", + help="Rolls dice mostly for Dungeons and Dragons type games. Usage: !roll 3d6+2", + brief="Simulate rolling dice" + ) +async def roll(ctx, dice_string): + dice_parts = dice_string.split('d') + num_dice = int(dice_parts[0]) + if '+' in dice_parts[1]: + die_parts = dice_parts[1].split('+') + die_size = int(die_parts[0]) + modifier = int(die_parts[1]) + elif '-' in dice_parts[1]: + die_parts = dice_parts[1].split('-') + die_size = int(die_parts[0]) + modifier = -int(die_parts[1]) + else: + die_size = int(dice_parts[1]) + modifier = 0 + + rolls = [random.randint(1, die_size) for i in range(num_dice)] + dice_str = ' + '.join([str(roll) for roll in rolls]) + total = sum(rolls) + modifier + + await ctx.send(f'{dice_str} + {modifier} = {total}' if modifier != 0 else f'{dice_str} = {total}') + +async def setup(bot): + bot.add_command(roll) + bot.add_command(poll) \ No newline at end of file diff --git a/sparkytron3000.py b/sparkytron3000.py index d0ed9d6..1db391e 100644 --- a/sparkytron3000.py +++ b/sparkytron3000.py @@ -185,7 +185,8 @@ async def chat_response(ctx, channel_vars, chat_history_string): await handle_error(error) async def folder_setup(): - folder_names = ["tmp", "tmp/sfw", "tmp/nsfw", "tmp/meme", "channels", "users", "channels/config", "channels/logs", "databases", "databases/currency", "databases/currency/players"] + # Only tmp, extensions and db are supported, all other folders only exist for backwards compatibility and will be removed soon! + folder_names = ["tmp", "extensions", "db", "plugins", "tmp/sfw", "tmp/nsfw", "tmp/meme", "channels", "users", "channels/config", "channels/logs", "databases", "databases/currency", "databases/currency/players"] for folder_name in folder_names: if not os.path.exists(folder_name): os.mkdir(folder_name) @@ -273,6 +274,10 @@ async def on_ready(): for plugin_file in os.listdir('plugins/'): if plugin_file != '__init__.py' and plugin_file[-3:] == '.py': await bot.load_extension(f'plugins.{plugin_file[:-3]}') + + for plugin_file in os.listdir('extensions/'): + if plugin_file != '__init__.py' and plugin_file[-3:] == '.py': + await bot.load_extension(f'plugins.{plugin_file[:-3]}') print('We have logged in as {0.user}'.format(bot)) #stuff to do if first run @@ -295,52 +300,6 @@ async def update_meme_webpage(filename): await upload_sftp("phixxy.com/ai-memes/index.html", server_folder, "index.html") os.rename(filename, 'tmp/' + new_file_name) - -@bot.command( - description="Poll", - help='Create a poll with up to 9 options. Usage: !poll "Put question here" "option 1" "option 2"', - brief="Enable or disable bot reactions" - ) -async def poll(ctx, question, *options: str): - if len(options) > 9: - await ctx.send("Error: You cannot have more than 9 options") - return - - embed = discord.Embed(title=question, colour=discord.Colour(0x283593)) - for i, option in enumerate(options): - embed.add_field(name=f"Option {i+1}", value=option, inline=False) - - message = await ctx.send(embed=embed) - numbers = {0: "\u0030\ufe0f\u20e3", 1: "\u0031\ufe0f\u20e3", 2: "\u0032\ufe0f\u20e3", 3: "\u0033\ufe0f\u20e3", 4: "\u0034\ufe0f\u20e3", 5: "\u0035\ufe0f\u20e3", 6: "\u0036\ufe0f\u20e3", 7: "\u0037\ufe0f\u20e3", 8: "\u0038\ufe0f\u20e3", 9: "\u0039\ufe0f\u20e3"} - for i in range(len(options)): - await message.add_reaction(numbers.get(i+1)) - -@bot.command( - description="Roll", - help="Rolls dice mostly for Dungeons and Dragons type games. Usage: !roll 3d6+2", - brief="Simulate rolling dice" - ) -async def roll(ctx, dice_string): - dice_parts = dice_string.split('d') - num_dice = int(dice_parts[0]) - if '+' in dice_parts[1]: - die_parts = dice_parts[1].split('+') - die_size = int(die_parts[0]) - modifier = int(die_parts[1]) - elif '-' in dice_parts[1]: - die_parts = dice_parts[1].split('-') - die_size = int(die_parts[0]) - modifier = -int(die_parts[1]) - else: - die_size = int(dice_parts[1]) - modifier = 0 - - rolls = [random.randint(1, die_size) for i in range(num_dice)] - dice_str = ' + '.join([str(roll) for roll in rolls]) - total = sum(rolls) + modifier - - await ctx.send(f'{dice_str} + {modifier} = {total}' if modifier != 0 else f'{dice_str} = {total}') - @bot.event async def on_reaction_add(reaction, user):