async def youareDel(self, ctx, *, roleName: str): # Get the role itself roleToGive = await getTextRoles(ctx, roleName, speak=True, sparcli=self.sparcli) if type(roleToGive) == int: return # Read from the server configs serverSettings = getServerJson(ctx.message.server.id) allowableIDs = serverSettings['SelfAssignableRoles'] if roleToGive.id in allowableIDs: allowableIDs.remove(roleToGive.id) else: await self.sparcli.say('This role cannot be self-assigned.') return # Plonk the settings back into the file storage serverSettings['SelfAssignableRoles'] = allowableIDs saveServerJson(ctx.message.server.id, serverSettings) # Print out to the user await self.sparcli.say( 'The role `{0.name}` with ID `{0.id}` can no longer be self-assigned.' .format(roleToGive))
async def deletionregex(self, ctx, *, regex:str=''): ''' Sets the deletion regex of the server ''' serverSettings = getServerJson(ctx.message.server.id) serverSettings['DeleteRegex'] = regex saveServerJson(ctx.message.server.id, serverSettings) await self.sparcli.say('Deletion regex has been updated.')
async def _add(self, ctx, user:Member, *, nickname:str=None): ''' Lets you force a username on a user ''' serverSettings = getServerJson(ctx.message.server.id) serverSettings['ForcedNicknames'][str(user.id)] = nickname saveServerJson(ctx.message.server.id, serverSettings) await self.sparcli.change_nickname(user, nickname) await self.sparcli.say('Nickname `{}` has been forced upon this user.'.format(nickname))
async def _rem(self, ctx, user:Member): ''' Removes a forced nickname from a user ''' serverSettings = getServerJson(ctx.message.server.id) try: del serverSettings['ForcedNicknames'][str(user.id)] except KeyError: await self.sparcli.say('This user doesn\'t have a forced nickname.') return saveServerJson(ctx.message.server.id, serverSettings) await self.sparcli.change_nickname(user, None) await self.sparcli.say('All forced nicknames have been removed from this user.')
async def botjoinrole(self, ctx, *, roleName: str): ''' Sets a role to be given to a user when they join ''' roleObject = await getTextRoles(ctx, roleName, speak=True, sparcli=self.sparcli) if type(roleObject) == int: return serverSettings = getServerJson(ctx.message.server.id) serverSettings['OnBotJoin'] = roleObject.id saveServerJson(ctx.message.server.id, serverSettings) await self.sparcli.say('Done!')
async def makestarboard(self, ctx): ''' Make a channel that works with the starboard setup ''' serverSettings = getServerJson(ctx.message.server.id) serverSettings['Toggles']['Starboard'] = True c = PermissionOverwrite(send_messages=False, add_reactions=False) d = PermissionOverwrite(send_messages=True, add_reactions=True) v = await self.sparcli.create_channel( ctx.message.server, 'starboard', (ctx.message.server.default_role, c), (ctx.message.server.me, d)) serverSettings['Channels']['Starboard'] = v.id saveServerJson(ctx.message.server.id, serverSettings) await self.sparcli.say('Done!')
async def prefixCommand(self, ctx, *, prefix: str): ''' Changes the command prefix for the server ''' # Set up some variables to keep line length short serverID = ctx.message.server.id # Load and save the command prefix serverSettings = getServerJson(serverID) serverSettings['CommandPrefix'] = prefix saveServerJson(serverID, serverSettings) # Print out to the user await self.sparcli.say( 'The command prefix for this server has been set to `{}`'.format( prefix))
async def fixjson(self, ctx): ''' Fixes all of the JSON config files ''' # Load up any changes that would have been made to the configs for server in self.sparcli.servers: z = getServerJson(server.id) z = fixJson(z) saveServerJson(server.id, z) # Reccursively fix any globals too z = getServerJson('Globals') z = fixJson(z) saveServerJson('Globals', z) await self.sparcli.say('Done.')
async def tagAdd(self, ctx, tagName, serverID=None, runWithExec=False): settings = getServerJson(serverID) zz = settings[{False: 'Tags', True: 'Etags'}[runWithExec]] if len(zz) > 30: await self.sparcli.say( 'There are already 30 tags on this server. You can\'t add any more.' ) return # Deal with idiots - trying to make tag without name if tagName == None: await self.sparcli.say('What is the tag name you want to add?') nameMessage = await self.sparcli.wait_for_message( author=ctx.message.author) tagName = nameMessage.content # If someone tries to tag a command if tagName[0] in [',', '👌']: return # Tell them thhat you're making tag and being nice await self.sparcli.say( 'Creating tag with name `{}`. What is the indended content?'. format(tagName)) contentMessage = await self.sparcli.wait_for_message( author=ctx.message.author) content = contentMessage.content if contentMessage.content != '' else contentMessage.attachments[ 0]['url'] # Get the serverID serverID = ctx.message.server.id if serverID == None else serverID # Save it into the server configs settings = getServerJson(serverID) settings[{ False: 'Tags', True: 'Etags' }[runWithExec]][tagName] = content saveServerJson(serverID, settings) # Respond to the user await self.sparcli.say('This tag has been created.')
async def tagDelete(self, ctx, tagName, serverID=None, runWithExec=False): # Deal with idiots - trying to make tag without name if tagName == None: await self.sparcli.say('What is the tag name you want to delete?') nameMessage = await self.sparcli.wait_for_message( author=ctx.message.author) tagName = nameMessage.content # Get the serverID serverID = ctx.message.server.id if serverID == None else serverID # Save it into the server configs settings = getServerJson(serverID) try: del settings[{False: 'Tags', True: 'Etags'}[runWithExec]][tagName] except KeyError: await self.sparcli.say('This tag does not exist.') return saveServerJson(serverID, settings) # Respond to the user await self.sparcli.say('This tag has been deleted.')
async def setup(self, ctx): ''' Gives you a reaction-based configuration dialogue ''' # Set up some variables to keep line length short author = ctx.message.author channel = ctx.message.channel serverID = ctx.message.server.id # Load current configuration serverSettings = getServerJson(serverID) defaultSettings = getServerJson('Default') # Make a lambda so I can easily check the author messageAuthor = lambda x: x.author.id == author.id # Work on each type of toggle enable toggleTypes = serverSettings['Toggles'].keys() toggleTypes = sorted(toggleTypes) channelTypes = defaultSettings['Channels'].keys() for i in toggleTypes: serverSettings = await updateFromEmoji( self.sparcli, ctx, serverSettings, i, serverSettings['Toggles'][i]) # See if you need to set it up with a channel if i in channelTypes and serverSettings['Toggles'][i] == True: serverSettings = await updateFromMessage( self.sparcli, ctx, serverSettings, i) # Tell the user that we're done await self.sparcli.say('Alright, everything is updated!') # Save it all to file saveServerJson(serverID, serverSettings)