Advertisement
Guest User

Untitled

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