async def setquotechannel(self, ctx, channel=None): """Sets the channel for quoted messages or disables it if no channel sent (admin only).""" # Check for admin status isAdmin = ctx.author.permissions_in(ctx.channel).administrator if not isAdmin: checkAdmin = self.settings.getServerStat(ctx.guild, "AdminArray") for role in ctx.author.roles: for aRole in checkAdmin: # Get the role that corresponds to the id if str(aRole['ID']) == str(role.id): isAdmin = True if not isAdmin: await ctx.send("You do not have permission to use this command.") return if channel == None: self.settings.setServerStat(ctx.message.guild, "QuoteChannel", None) msg = 'Quote channel *disabled*.' await ctx.channel.send(msg) return channel = DisplayName.channelForName(channel, ctx.guild, "text") if channel == None: await ctx.send("I couldn't find that channel :(") return self.settings.setServerStat(ctx.message.guild, "QuoteChannel", channel.id) msg = 'Quote channel set to {}'.format(channel.mention) await ctx.channel.send(msg)
async def setvkchannel(self, ctx, *, channel = None): """Sets which channel then mention posts to when enough votes against a user are reached.""" isAdmin = ctx.message.author.permissions_in(ctx.message.channel).administrator if not isAdmin: checkAdmin = self.settings.getServerStat(ctx.message.guild, "AdminArray") for role in ctx.message.author.roles: for aRole in checkAdmin: # Get the role that corresponds to the id if str(aRole['ID']) == str(role.id): isAdmin = True # Only allow admins to change server stats if not isAdmin: await ctx.channel.send('You do not have sufficient privileges to access this command.') return if channel == None: self.settings.setServerStat(ctx.guild, "VoteKickChannel", None) await ctx.send("Removed the vote kick channel.") return check_channel = DisplayName.channelForName(channel, ctx.guild, "text") if check_channel: self.settings.setServerStat(ctx.guild, "VoteKickChannel", check_channel.id) await ctx.send("Vote kick will now be mentioned in *{}.*".format(check_channel.mention)) return await ctx.send("I couldn't find *{}*...".format(Nullify.clean(channel)))
async def settelechannel(self, ctx, *, channel=None): """Sets the channel for telephone commands - or disables that if nothing is passed (admin only).""" isAdmin = ctx.message.author.permissions_in( ctx.message.channel).administrator # Only allow admins to change server stats if not isAdmin: await ctx.channel.send( 'You do not have sufficient privileges to access this command.' ) return if channel == None: self.settings.setServerStat(ctx.message.guild, "TeleChannel", "") self.settings.setServerStat(ctx.guild, "TeleNumber", None) msg = ':telephone: *disabled*.' await ctx.channel.send(msg) return channel = DisplayName.channelForName(channel, ctx.guild, "text") if channel == None: await ctx.send("I couldn't find that channel :(") return self.settings.setServerStat(ctx.message.guild, "TeleChannel", channel.id) teleNumber = self._getsafenumber( str(channel.id)[len(str(channel.id)) - 7:], ctx.guild) self.settings.setServerStat(ctx.guild, "TeleNumber", teleNumber) msg = ':telephone: channel set to **{}**.'.format(channel.name) await ctx.channel.send(msg)
def _gettelechannel(self, server): teleChannel = self.settings.getServerStat(server, "TeleChannel") if teleChannel: teleChannel = DisplayName.channelForName(str(teleChannel), server, "text") if teleChannel == "": return None return teleChannel
async def sscreatechannels(self, ctx, *, category=None): """Creates the private channels for all users with the Secret Santa role under the supplied category (bot-admin only).""" if not self.settings.getServerStat(ctx.guild, "SSAllowed", False): return await ctx.send( "The Secret Santa module has not been allowed on this server.\nOne of my owners can enable it with `{}allowss yes`." .format(ctx.prefix)) if not await Utils.is_bot_admin_reply(ctx): return # Check if our category exists - if not, create it if not category: return await ctx.send( 'You must supply a category for the Secret Santa channels.') category_name = category # Save for later category = DisplayName.channelForName(category_name, ctx.guild, "category") if not category: # Create it category = await ctx.guild.create_category_channel(category_name) suppress = True if self.settings.getServerStat( ctx.guild, "SuppressMentions", True) else False # Make sure we even have a role setup and that it's valid role = self.settings.getServerStat(ctx.guild, "SSRole", "") if role in [None, ""]: return await ctx.send( "There is no Secret Santa role set. You can set it with the `{}setssrole [role]` command." .format(ctx.prefix)) # Verify it corresponds to a real role arole = next((x for x in ctx.guild.roles if str(x.id) == str(role)), None) if not arole: return await ctx.send( "There is no role that matches id: `{}`. You can change this with the `{}setssrole [role]` command." .format(role, ctx.prefix)) # We have a clean slate - let's get a list of non-bot users with the SSRole participants = [ x for x in ctx.guild.members if not x.bot and arole in x.roles ] # Verify we have a minimum of 3 participants - otherwise we can't randomize if len(participants) < 3: # No one has the role, it seems. msg = "Not enough users are participating in the Secret Santa drawing - 3 or more need the **{}** role to participate.".format( arole.name) return await ctx.send(Utils.suppressed(ctx, msg)) m = await ctx.send("Iterating and adding Secret Santa channels...") # We now have a clean slate, valid role, and enough particpiants - let's create the channels channels = 0 for x in participants: # Create a channel with the user's id as the name overwrites = { ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False), x: discord.PermissionOverwrite(read_messages=True) } channel = await ctx.guild.create_text_channel( str(x.id), overwrites=overwrites, category=category) channels += 1 await self._channel_message(channel, x) await m.edit(content="Created {} Secret Santa channel{}!".format( channels, "" if channels == 1 else "s"))
async def ssremovechannels(self, ctx, *, category=None): """Removes all Secret Santa channels under a given category whose names correspond to active user's id (bot-admin only).""" if not self.settings.getServerStat(ctx.guild, "SSAllowed", False): return await ctx.send( "The Secret Santa module has not been allowed on this server.\nOne of my owners can enable it with `{}allowss yes`." .format(ctx.prefix)) if not await Utils.is_bot_admin_reply(ctx): return if not category: return await ctx.send( 'You must supply the category for the Secret Santa channels.') category = DisplayName.channelForName(category, ctx.guild, "category") if not category: return await ctx.send("I couldn't locate that category...") m = await ctx.send("Iterating and removing Secret Santa channels...") channels_total = len(category.channels) channels_removed = 0 channels_located = 0 for x in category.text_channels: try: name = int(x.name) except: continue member = ctx.guild.get_member(name) if not member: # Channel name doesn't correspond with an existing member continue channels_located += 1 # Remove the channel try: await x.delete( reason= "Secret Santa channel removed per the ssremovechannels command." ) channels_removed += 1 except: continue # Remove the category channel if the removed and located channels were the same length cat_removed = False if channels_total == channels_removed: try: await category.delete( reason= "Secret Santa channel removed per the ssremovechannels command." ) cat_removed = True except: pass # Give some stats! msg = "Out of {} channel{}, {} {} resovled to user ids, {} {} removed. The category was {} removed.".format( channels_total, "" if channels_total == 1 else "s", channels_located, "was" if channels_located == 1 else "were", channels_removed, "was" if channels_removed == 1 else "were", "also" if cat_removed else "not") # List our stats await m.edit(content=msg)
async def ssrevert(self, ctx, *, category=None): """Returns ownership of the Secret Santa channels to their original owners if found (bot-admin only).""" if not self.settings.getServerStat(ctx.guild, "SSAllowed", False): return await ctx.send( "The Secret Santa module has not been allowed on this server.\nOne of my owners can enable it with `{}allowss yes`." .format(ctx.prefix)) # Verify perms - bot-admin if not self.is_bot_admin(ctx): await ctx.send( 'You do not have sufficient privileges to access this command.' ) return # Check if our category exists - if not, create it if not category: await ctx.send( 'You must supply a category for the Secret Santa channels.') return category = DisplayName.channelForName(category, ctx.guild, "category") if not category: await ctx.send("I couldn't locate that category...") return m = await ctx.send("Iterating and removing Secret Santa channels...") channels_total = len(category.channels) channels_reverted = 0 channels_located = 0 for x in category.text_channels: try: name = int(x.name) except: # Not following our naming convention - ignore continue channels_located += 1 overs = x.overwrites # Walk the overwrites and remove them all for over in overs: # Only adjust user overwrites if not isinstance(over, discord.Member): continue await x.set_permissions(over, overwrite=None) # Try to get our original member member = ctx.guild.get_member(name) if not member: # Channel name doesn't correspond with an existing member continue # We got a member - let's set their overwrites await x.set_permissions(member, read_messages=True) channels_reverted += 1 # Give some stats! msg = "Out of {} channel{}, {} {} resovled to user ids, {} {} reverted.".format( channels_total, "" if channels_total == 1 else "s", channels_located, "was" if channels_located == 1 else "were", channels_reverted, "was" if channels_reverted == 1 else "were") # List our stats await m.edit(content=msg)
async def quotechannel(self, ctx): """Prints the current quote channel.""" qChan = self.settings.getServerStat(ctx.guild, "QuoteChannel") if not qChan: await ctx.send("Quoting is currently *disabled*.") return channel = DisplayName.channelForName(str(qChan), ctx.guild, "text") if channel: await ctx.send("The current quote channel is {}".format(channel.mention)) return await ctx.send("Channel id: *{}* no longer exists on this server. Consider updating this setting!".format(qChan))
async def telechannel(self, ctx): """Prints the current channel for telephone commands.""" teleChan = self.settings.getServerStat(ctx.guild, "TeleChannel") if not teleChan: await ctx.send(":telephone: is currently *disabled*.") return channel = DisplayName.channelForName(str(teleChan), ctx.guild, "text") if channel: await ctx.send("The current :telephone: channel is {}".format(channel.mention)) return await ctx.send("Channel id: *{}* no longer exists on this server. Consider updating this setting!".format(teleChan))
async def setquotechannel(self, ctx, channel=None): """Sets the channel for quoted messages or disables it if no channel sent (admin only).""" if not await Utils.is_bot_admin_reply(ctx): return if channel == None: self.settings.setServerStat(ctx.guild, "QuoteChannel", None) msg = 'Quote channel *disabled*.' return await ctx.send(msg) channel = DisplayName.channelForName(channel, ctx.guild, "text") if channel == None: return await ctx.send("I couldn't find that channel :(") self.settings.setServerStat(ctx.guild, "QuoteChannel", channel.id) msg = 'Quote channel set to {}'.format(channel.mention) await ctx.send(msg)
async def join(self, ctx, *, channel = None): """Joins a voice channel.""" delay = self.settings.getServerStat(ctx.guild, "MusicDeleteDelay", 20) if channel == None: if not ctx.author.voice: return await Message.EmbedText(title="♫ You need to pass a voice channel for me to join!",color=ctx.author,delete_after=delay).send(ctx) channel = ctx.author.voice.channel else: channel = DisplayName.channelForName(channel, ctx.guild, "voice") if not channel: return await Message.EmbedText(title="♫ I couldn't find that voice channel!",color=ctx.author,delete_after=delay).send(ctx) player = self.bot.wavelink.get_player(ctx.guild.id) if player.is_connected: if not (player.paused or player.is_playing): await player.connect(channel.id) return await Message.EmbedText(title="♫ Ready to play music in {}!".format(channel),color=ctx.author,delete_after=delay).send(ctx) else: return await Message.EmbedText(title="♫ I'm already playing music in {}!".format(ctx.guild.get_channel(int(player.channel_id))),color=ctx.author,delete_after=delay).send(ctx) await player.connect(channel.id) await Message.EmbedText(title="♫ Ready to play music in {}!".format(channel),color=ctx.author,delete_after=delay).send(ctx)
async def ssgenreport(self, ctx, *, category=None): """Randomly pairs users for Secret Santa and uploads a ss.json report (bot-admin only).""" if not self.settings.getServerStat(ctx.guild, "SSAllowed", False): return await ctx.send( "The Secret Santa module has not been allowed on this server.\nOne of my owners can enable it with `{}allowss yes`." .format(ctx.prefix)) # We need to make sure that we have channels setup, they're all valid, and the correspond to existing users with # the SSRole if not await Utils.is_bot_admin_reply(ctx): return if not category: return await ctx.send( 'You must supply the category for the Secret Santa channels.') category = DisplayName.channelForName(category, ctx.guild, "category") if not category: return await ctx.send("I couldn't locate that category...") suppress = True if self.settings.getServerStat( ctx.guild, "SuppressMentions", True) else False # Get our users by resolving the text channel names to user ids, then shuffle m = await ctx.send("Gathering and shuffling participants...") participants = [] for x in category.text_channels: try: name = int(x.name) except: continue member = ctx.guild.get_member(name) if not member: # Channel name doesn't correspond with an existing member continue participants.append(member) if len(participants) < 3: await ctx.send( "Not enough channels resolved to users for the Secret Santa drawing. 3 or more are required." ) return # Shuffle the list, copy it, and rotate one to the right random.shuffle(participants) partners = participants[1:] partners.append(participants[0]) results = { "category": { "name": category.name, "id": category.id }, "swaps": [] } await m.edit(content="Organizing results...") for x in range(len(participants)): results["swaps"].append({ "to_name": participants[x].name + "#" + participants[x].discriminator, "to_id": participants[x].id, "from_name": partners[x].name + "#" + partners[x].discriminator, "from_id": partners[x].id }) # results = dict(zip(participants,partners)) await m.edit( content="Generating and uploading Secret_Santa_{}.json...".format( ctx.guild.id)) # Save it as a json file and upload json.dump(results, open("Secret_Santa_{}.json".format(ctx.guild.id), "w"), indent=2) # Upload it await ctx.send(file=discord.File( fp="Secret_Santa_{}.json".format(ctx.guild.id), filename="Secret_Santa_{}.json".format(ctx.guild.id))) # Remove the file os.remove("Secret_Santa_{}.json".format(ctx.guild.id)) # Remove the prior message await m.delete()