Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.42 KB | None | 0 0
  1.     @commands.command(pass_context=True, name="softlock")
  2.     async def softlock(self, ctx, *, channels=""):
  3.         """Lock message sending in the channel, without the "disciplinary action" note. Staff and Helpers only."""
  4.         issuer = ctx.message.author
  5.         ishelper = None
  6.         if (self.bot.helpers_role not in issuer.roles) and (self.bot.staff_role not in issuer.roles):
  7.             msg = "{0} This command is limited to Staff and Helpers.".format(issuer.mention)
  8.             await self.bot.say(msg)
  9.             return
  10.         ishelper = self.bot.staff_role not in issuer.roles
  11.         try:
  12.             if len(ctx.message.channel_mentions) == 0:
  13.                 channels = [ctx.message.channel]                   
  14.                 if (ishelper) and (ctx.message.channel not in self.bot.assistance_channels):  
  15.                     msg = "{0} Helpers cannot use this command outside of the assistance channels.".format(issuer.mention)
  16.                     await self.bot.say(msg)
  17.                     return
  18.             else:
  19.                 channels = ctx.message.channel_mentions
  20.                 if (ishelper) and (channels not in self.bot.assistance_channels):
  21.                     msg = "{0} Helpers cannot use this command to lock other channels.".format(issuer.mention)
  22.                     await self.bot.say(msg)
  23.                     return 
  24.             locked_down = []
  25.             for c in channels:
  26.                 overwrites_everyone = c.overwrites_for(self.bot.everyone_role)
  27.                 overwrites_helpers = c.overwrites_for(self.bot.everyone_role)
  28.                 if overwrites_everyone.send_messages is False:
  29.                     await self.bot.say("🔒 {} is already locked down. Use `.unlock` to unlock.".format(c.mention))
  30.                     continue
  31.                 overwrites_everyone.send_messages = False
  32.                 overwrites_helpers.send_messages = ishelper
  33.                 await self.bot.edit_channel_permissions(c, self.bot.everyone_role, overwrites_everyone)
  34.                 await self.bot.edit_channel_permissions(c, self.bot.helpers_role, overwrites_helpers)
  35.                 await self.bot.send_message(c, "🔒 Channel locked.")
  36.                 locked_down.append(c)
  37.             msg = "🔒 **Soft-lock**: {1} soft-locked channels | {2}#{3}\n📝 __Channels__: {0}".format(', '.join(c.mention for c in locked_down), ctx.message.author.mention, ctx.message.author.name, ctx.message.author.discriminator)
  38.             await self.bot.send_message(self.bot.modlogs_channel, msg)
  39.         except discord.errors.Forbidden:
  40.             await self.bot.say("💢 I don't have permission to do this.")
  41.  
  42.     @commands.command(pass_context=True, name="unlock")
  43.     async def unlock(self, ctx, *, channels=""):
  44.         """Unlock message sending in the channel. Staff only and Helpers only."""
  45.         issuer = ctx.message.author
  46.         if (self.bot.helpers_role not in issuer.roles) and (self.bot.staff_role not in issuer.roles):
  47.             msg = "{0} This command is limited to Staff and Helpers.".format(issuer.mention)
  48.             await self.bot.say(msg)
  49.             return
  50.         try:
  51.             if len(ctx.message.channel_mentions) == 0:
  52.                 channels = [ctx.message.channel]                   
  53.                 if (self.bot.staff_role not in issuer.roles) and (ctx.message.channel not in self.bot.assistance_channels):  
  54.                     msg = "{0} Helpers cannot use this command outside of the assistance channels.".format(issuer.mention)
  55.                     await self.bot.say(msg)
  56.                     return
  57.             else:
  58.                 channels = ctx.message.channel_mentions
  59.                 if (self.bot.staff_role not in issuer.roles) and (channels not in self.bot.assistance_channels):
  60.                     msg = "{0} Helpers cannot use this command to unlock other channels.".format(issuer.mention)
  61.                     await self.bot.say(msg)
  62.                     return
  63.             unlocked = []
  64.             for c in channels:
  65.                 overwrites_everyone = c.overwrites_for(self.bot.everyone_role)
  66.                 overwrites_staff = c.overwrites_for(self.bot.staff_role)
  67.                 overwrites_helpers = c.overwrites_for(self.bot.helpers_role)
  68.                 if overwrites_everyone.send_messages is None:
  69.                     await self.bot.say("🔓 {} is already unlocked.".format(c.mention))
  70.                     return
  71.                 overwrites_everyone.send_messages = None
  72.                 overwrites_staff.send_messages = True                
  73.                 overwrites_helpers.send_messages = None
  74.                 await self.bot.edit_channel_permissions(c, self.bot.everyone_role, overwrites_everyone)
  75.                 await self.bot.edit_channel_permissions(c, self.bot.staff_role, overwrites_staff)
  76.                 await self.bot.edit_channel_permissions(c, self.bot.helpers_role, overwrites_helpers)
  77.                 await self.bot.send_message(c, "🔓 Channel unlocked.")
  78.                 unlocked.append(c)
  79.             msg = "🔓 **Unlock**: {1} unlocked channels | {2}#{3}\n📝 __Channels__: {0}".format(', '.join(c.mention for c in unlocked), ctx.message.author.mention, ctx.message.author.name, ctx.message.author.discriminator)
  80.             await self.bot.send_message(self.bot.modlogs_channel, msg)
  81.         except discord.errors.Forbidden:
  82.             await self.bot.say("💢 I don't have permission to do this.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement