From a74c15e73a3e952189efd1820d7cee99e09107e4 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Mon, 16 Sep 2019 12:39:41 -0700 Subject: [PATCH] [Region] Initial commit --- README.md | 2 ++ region/__init__.py | 5 +++++ region/region.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 region/__init__.py create mode 100644 region/region.py diff --git a/README.md b/README.md index 4dfc88e..0be72c5 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ pingtime - Show all shards' pingtimes. pupper - A cog for Ryan5374. A pet that comes around on an on_message listener and waits for someone to pet it (react with a standard wave emoji), and rewards with credits. Many attributes are configurable. +region - A command to change the voice region of a server. Requires the guild admin or mod role or guild administrator. + retrosign - A v3 port of Anismash's retrosign cog: https://github.com/Anismash/Ani-Cogs/tree/master/retrosign rndstatus - A v3 port of Twentysix's rndstatus cog with a couple extra settings. diff --git a/region/__init__.py b/region/__init__.py new file mode 100644 index 0000000..87eedca --- /dev/null +++ b/region/__init__.py @@ -0,0 +1,5 @@ +from .region import Region + + +def setup(bot): + bot.add_cog(Region()) diff --git a/region/region.py b/region/region.py new file mode 100644 index 0000000..768b0aa --- /dev/null +++ b/region/region.py @@ -0,0 +1,48 @@ +import discord +from redbot.core import checks, commands +from redbot.core.utils.chat_formatting import humanize_list + + +class Region(commands.Cog): + """Change the guild voice region.""" + + @checks.mod_or_permissions(administrator=True) + @commands.cooldown(1, 60, discord.ext.commands.BucketType.guild) + @commands.command() + async def region(self, ctx, *, region: str): + """Set the current guild's voice region.""" + regions = [ + "japan", + "singapore", + "eu-central", + "india", + "us-central", + "london", + "eu-west", + "amsterdam", + "brazil", + "dubai", + "us-west", + "hongkong", + "us-south", + "southafrica", + "us-east", + "sydney", + "frankfurt", + "russia", + ] + region = region.replace(" ", "-") + if region not in regions: + ctx.command.reset_cooldown(ctx) + return await ctx.send( + f"`{region}` was not found in the list of Discord voice regions. Valid regions are: {humanize_list(regions)}." + ) + try: + await ctx.guild.edit(region=region) + except discord.errors.Forbidden: + return await ctx.send("I don't have permissions to edit this guild's settings.") + except discord.errors.HTTPException: + return await ctx.send(f"Error: An invalid server region was passed: `{region}`") + await ctx.send( + f"The voice server region for `{ctx.guild.name}` has been changed to `{region}`." + )