From 473995f8bfe1eec6da6817e0ea17748fde425667 Mon Sep 17 00:00:00 2001 From: Haku Date: Mon, 20 Jun 2022 18:22:32 -0400 Subject: [PATCH] initial commit --- .gitignore | 1 + libcordroster/__init__.py | 7 ++++++ libcordroster/info.json | 18 ++++++++++++++ libcordroster/libcordroster.py | 44 ++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 libcordroster/__init__.py create mode 100644 libcordroster/info.json create mode 100644 libcordroster/libcordroster.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..745f61c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/libcordroster/__init__.py b/libcordroster/__init__.py new file mode 100644 index 0000000..edc7acd --- /dev/null +++ b/libcordroster/__init__.py @@ -0,0 +1,7 @@ +from redbot.core.bot import Red +from .libcordroster import LibcordRoster + + +def setup(bot: Red): + cog = LibcordRoster(bot) + bot.add_cog(cog) diff --git a/libcordroster/info.json b/libcordroster/info.json new file mode 100644 index 0000000..b9a00f6 --- /dev/null +++ b/libcordroster/info.json @@ -0,0 +1,18 @@ +{ + "author": [ + "Haku" + ], + "name": "Libcord Roster", + "bot_version": [ + 3, + 0, + 0 + ], + "description": "Libcord roster.", + "hidden": false, + "install_msg": "Libcord roster successfully installed.", + "short": "Libcord roster Stuff", + "tags": [ + "fun" + ] +} \ No newline at end of file diff --git a/libcordroster/libcordroster.py b/libcordroster/libcordroster.py new file mode 100644 index 0000000..596c0dd --- /dev/null +++ b/libcordroster/libcordroster.py @@ -0,0 +1,44 @@ +from redbot.core import commands +from redbot.core.bot import Red +from redbot.core.utils.chat_formatting import pagify +import discord + + +async def has_update_command_role(ctx): + """ + Checks if the user has the update command role. + """ + if ctx.guild is None: + return False + uc_role = discord.utils.get(ctx.guild.roles, name="Update Command") + reporter_role = discord.utils.get(ctx.guild.roles, name="Reporter") + if uc_role is None: + return False + return (uc_role in ctx.author.roles) or (reporter_role in ctx.author.roles) + + +class LibcordRoster(commands.Cog): + + def __init__(self, bot: Red, *args, **kwargs): + super().__init__(*args, **kwargs) + self.bot = bot + + def cog_unload(self): + pass + + @commands.command() + @commands.check(has_update_command_role) + async def roster(self, ctx: commands.Context): + """Get the names of all users with the Updating role""" + guild = ctx.guild + role = discord.utils.get(guild.roles, name="Updating") + members = [member for member in guild.members if role in member.roles] + out = "" + for member in members: + if member.nick: + out += f"{member.nick}\n" + elif member.name: + out += f"{member.name}\n" + out = '\n'.join(sorted(out.splitlines(), key=str.lower)) + for page in pagify(out): + await ctx.send("```\n" + page + "```")