コード例 #1
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def muteRole(self, ctx:commands.Context, role:discord.Role):
     """Sets what role to use for mutes"""
     guild:discord.Guild = ctx.guild
     perms = guild.me.guild_permissions
     if not perms.manage_roles:
         await ctx.send("I require the 'manage_roles' permission to be able to add the role to people.")
         return
     if not guild.me.top_role > role:
         await ctx.send(f"I need a role that is higher then the {role.mention} role to be able to add it to people.")
         return
     Configuration.setConfigVar(ctx.guild.id, "MUTE_ROLE", int(role.id))
     await ctx.send(f"{role.mention} will now be used for muting people, denying send permissions for the role.")
     failed = []
     for channel in guild.text_channels:
         try:
             await channel.set_permissions(role, reason="Automatic mute role setup", send_messages=False, add_reactions=False)
         except discord.Forbidden as ex:
             failed.append(channel.mention)
     for channel in guild.voice_channels:
         try:
             await channel.set_permissions(role, reason="Automatic mute role setup", speak=False, connect=False)
         except discord.Forbidden as ex:
             failed.append(f"Voice channel {channel.name}")
     if len(failed) > 0:
         message = f"I was unable to configure muting in the following channels, there probably is an explicit deny on that channel for 'manage channel' on those channels or their category (if they are synced) for one of my roles (includes everyone role). Please make sure I can manage those channels and run this command again or deny the `send_messages` and `add_reactions` permissions for {role.mention} manually.\n"
         for fail in failed:
             if len(message) + len(fail) > 2048:
                 await ctx.send(message)
                 message = ""
             message = message + fail
         if len(message) > 0:
             await ctx.send(message)
     else:
         await ctx.send(f"Automatic mute setup complete.")
コード例 #2
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def add(self, ctx:commands.Context, role:discord.Role):
     current = Configuration.getConfigVar(ctx.guild.id, "SELF_ROLES")
     if role.id in current:
         await ctx.send("This role is already assignable.")
     else:
         current.append(role.id)
         Configuration.setConfigVar(ctx.guild.id, "SELF_ROLES", current)
         await ctx.send(f"The {role.name} role is now assignable.")
コード例 #3
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def removeIgnoredUser(self, ctx:commands.Context, user:discord.User):
     current = Configuration.getConfigVar(ctx.guild.id, "IGNORED_USERS")
     if user.id not in current:
         await ctx.send("This user was not on my ignore list.")
     else:
         current.remove(user.id)
         Configuration.setConfigVar(ctx.guild.id, "IGNORED_USERS", current)
         await ctx.send("I will now no longer ignore this user's edited/deleted messages.")
コード例 #4
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def addIgnoredUser(self, ctx:commands.Context, user:discord.Member):
     current = Configuration.getConfigVar(ctx.guild.id, "IGNORED_USERS")
     if user.id in current:
         await ctx.send("This user is already ignored.")
     else:
         current.append(user.id)
         Configuration.setConfigVar(ctx.guild.id, "IGNORED_USERS", current)
         await ctx.send("I will now no longer log this user's edited/deleted messages.")
コード例 #5
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def remove_from_whitelist(self, ctx: commands.Context, server:int):
     current = Configuration.getConfigVar(ctx.guild.id, "INVITE_WHITELIST")
     if server not in current:
         await ctx.send("This server was not whitelisted.")
     else:
         current.remove(server)
         Configuration.setConfigVar(ctx.guild.id, "INVITE_WHITELIST", current)
         await ctx.send(f"Server {server} is no longer whitelisted.")
コード例 #6
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def add_to_whitelist(self, ctx: commands.Context, server:int):
     current = Configuration.getConfigVar(ctx.guild.id, "INVITE_WHITELIST")
     if server in current:
         await ctx.send("This server is already whitelisted.")
     else:
         current.append(server)
         Configuration.setConfigVar(ctx.guild.id, "INVITE_WHITELIST", current)
         await ctx.send(f"Server {server} is now whitelisted.")
コード例 #7
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def remove(self, ctx:commands.Context, role:discord.Role):
     current = Configuration.getConfigVar(ctx.guild.id, "SELF_ROLES")
     if role.id not in current:
         await ctx.send("This wasn't assignable.")
     else:
         current.remove(role.id)
         Configuration.setConfigVar(ctx.guild.id, "SELF_ROLES", current)
         await ctx.send(f"The {role.name} role is now no longer assignable.")
コード例 #8
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def mute(self, ctx:commands.Context):
     """Disable the mute feature"""
     role = discord.utils.get(ctx.guild.roles, id=Configuration.getConfigVar(ctx.guild.id, "MUTE_ROLE"))
     if role is not None:
         for member in role.members:
             await member.remove_roles(role, reason=f"Mute feature has been disabled")
     Configuration.setConfigVar(ctx.guild.id, "MUTE_ROLE", 0)
     await ctx.send("Mute feature has been disabled, all people muted have been unmuted and the role can now be removed.")
コード例 #9
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def prefix(self, ctx:commands.Context, *, new_prefix:str = None):
     """Sets or show the server prefix"""
     if new_prefix is None:
         await ctx.send(f"The current server prefix is `{Configuration.getConfigVar(ctx.guild.id, 'PREFIX')}`")
     elif len(new_prefix) > 25:
         await ctx.send("Please use a shorter prefix.")
     else:
         Configuration.setConfigVar(ctx.guild.id, "PREFIX", new_prefix)
         await ctx.send(f"{Emoji.get_chat_emoji('YES')} The server prefix is now `{new_prefix}`.")
コード例 #10
0
 async def mute_role(self, ctx: commands.Context, role: discord.Role):
     """configure_mute_help"""
     if role == ctx.guild.default_role:
         return await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate(f'default_role_forbidden', ctx)}"
         )
     guild: discord.Guild = ctx.guild
     perms = guild.me.guild_permissions
     if not perms.manage_roles:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('mute_missing_perm', ctx)}"
         )
         return
     if not guild.me.top_role > role:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('mute_missing_perm', ctx, role=role.mention)}"
         )
         return
     Configuration.setConfigVar(ctx.guild.id, "MUTE_ROLE", int(role.id))
     await ctx.send(
         f"{Emoji.get_chat_emoji('YES')} {Translator.translate('mute_role_confirmation', ctx, role=role.mention)}"
     )
     failed = []
     for channel in guild.text_channels:
         try:
             await channel.set_permissions(role,
                                           reason=Translator.translate(
                                               'mute_setup', ctx),
                                           send_messages=False,
                                           add_reactions=False)
         except discord.Forbidden as ex:
             failed.append(channel.mention)
     for channel in guild.voice_channels:
         try:
             await channel.set_permissions(role,
                                           reason=Translator.translate(
                                               'mute_setup', ctx),
                                           speak=False,
                                           connect=False)
         except discord.Forbidden as ex:
             failed.append(
                 Translator.translate('voice_channel',
                                      ctx,
                                      channel=channel.name))
     if len(failed) > 0:
         message = f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('mute_setup_failures', ctx, role=role.mention)}\n"
         for fail in failed:
             if len(message) + len(fail) > 2048:
                 await ctx.send(message)
                 message = ""
             message = message + fail
         if len(message) > 0:
             await ctx.send(message)
     else:
         await ctx.send(
             f"{Emoji.get_chat_emoji('YES')} {Translator.translate('mute_setup_complete', ctx)}"
         )
コード例 #11
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def modLogChannel(self, ctx: commands.Context, channel: discord.TextChannel):
     """Sets the logging channel for modlogs (mute/kick/ban/...)"""
     permissions = channel.permissions_for(ctx.guild.get_member(self.bot.user.id))
     if permissions.read_messages and permissions.send_messages:
         Configuration.setConfigVar(ctx.guild.id, "MOD_LOGS", channel.id)
         await ctx.send(f"{channel.mention} will now be used for mod logs")
     else:
         await ctx.send(
             f"I cannot use {channel.mention} for logging, I do not have the required permissions in there (read_messages, send_messages).")
コード例 #12
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def language(self, ctx, lang_code:str = None):
     """language_help"""
     if lang_code is None:
         await ctx.send(f"See https://crowdin.com/project/gearbot for all available languages and their translation statuses")
     else:
         if lang_code in Translator.LANGS:
             Configuration.setConfigVar(ctx.guild.id, "LANG", lang_code)
             await ctx.send(f"{Emoji.get_chat_emoji('YES')} {Translator.translate('lang_changed', ctx.guild.id, lang=lang_code)}")
         else:
             await ctx.send(f"{Emoji.get_chat_emoji('MUTE')} {Translator.translate('lang_unknown', ctx.guild.id)}")
コード例 #13
0
ファイル: Serveradmin.py プロジェクト: alexandrutodea/Gearbot
 async def minorLogChannel(self, ctx: commands.Context, channel: discord.TextChannel):
     """Sets the logging channel for minor logs (edit/delete)"""
     if channel is None:
         raise BadArgument("Missing channel")
     permissions = channel.permissions_for(ctx.guild.get_member(self.bot.user.id))
     if permissions.read_messages and permissions.send_messages and permissions.embed_links:
         old = Configuration.getConfigVar(ctx.guild.id, "MINOR_LOGS")
         Configuration.setConfigVar(ctx.guild.id, "MINOR_LOGS", channel.id)
         await ctx.send(f"{channel.mention} will now be used for minor logs.")
         if old == 0:
             await ctx.send(f"Caching recent messages for logging...")
             self.bot.to_cache.append(ctx)
     else:
         await ctx.send(
             f"I cannot use {channel.mention} for logging, I do not have the required permissions in there (read_messages, send_messages and embed_links).")
コード例 #14
0
 async def prefix(self, ctx: commands.Context, *, new_prefix: str = None):
     """Sets or show the server prefix"""
     if new_prefix is None:
         await ctx.send(
             f"{Translator.translate('current_server_prefix', ctx, prefix=Configuration.getConfigVar(ctx.guild.id, 'PREFIX'))}"
         )
     elif len(new_prefix) > 25:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('prefix_too_long', ctx)}"
         )
     else:
         Configuration.setConfigVar(ctx.guild.id, "PREFIX", new_prefix)
         await ctx.send(
             f"{Emoji.get_chat_emoji('YES')} {Translator.translate('prefix_set', ctx, new_prefix=new_prefix)}"
         )
コード例 #15
0
async def set_log_channel(ctx, channel, log_type, permissions=None):
    if permissions is None:
        permissions = ["read_messages", "send_messages"]
    channel_permissions = channel.permissions_for(
        ctx.guild.get_member(ctx.bot.user.id))
    if all(getattr(channel_permissions, perm) for perm in permissions):
        Configuration.setConfigVar(ctx.guild.id, f"{log_type}_LOGS".upper(),
                                   channel.id)
        await ctx.send(
            f"{Emoji.get_chat_emoji('YES')} {Translator.translate(f'{log_type}_log_channel_set', ctx, channel=channel.mention)}"
        )
        return True
    else:
        await ctx.send(
            f"{Emoji.get_chat_emoji('NO')} {Translator.translate('missing_perms_in_channel', ctx, perms1=', '.join(permissions[:-1]), perms2=permissions[-1:])}"
        )
        return False
コード例 #16
0
 async def disablejoinLogChannel(self, ctx: commands.Context):
     """Disables join/leave logs"""
     Configuration.setConfigVar(ctx.guild.id, "JOIN_LOGS", 0)
     await ctx.send("Join logs have been disabled.")
コード例 #17
0
 async def disablemodLogChannel(self, ctx: commands.Context):
     """Disables the modlogs (mute/kick/ban/...)"""
     Configuration.setConfigVar(ctx.guild.id, "MOD_LOGS", 0)
     await ctx.send("Mod logs have been disabled.")
コード例 #18
0
 async def disableMinorLogChannel(self, ctx: commands.Context):
     """Disables minor logs (edit/delete)"""
     Configuration.setConfigVar(ctx.guild.id, "MINOR_LOGS", 0)
     await ctx.send("Minor logs have been disabled.")
コード例 #19
0
 async def perm_denied_message(self, ctx, value: bool):
     """perm_denied_message_help"""
     Configuration.setConfigVar(ctx.guild.id, "PERM_DENIED_MESSAGE", value)
     await ctx.send(
         f"{Emoji.get_chat_emoji('YES')} {Translator.translate('configure_perm_msg_' + ('enabled' if value else 'disabled'), ctx.guild.id)}"
     )