示例#1
0
 async def _vq(message, command, silent=False):
     """List voice channel queue
 Usage: !vq"""
     if not await Util.check_args_count(
             message, command, silent, min=1, max=1):
         return
     if not bc.voice_client_queue:
         e = DiscordEmbed()
         e.title("🔊 Voice queue 🔊")
         e.color(0xcc1818)
         e.description("<empty>")
         return null(await Msg.response(message,
                                        None,
                                        silent,
                                        embed=e.get()))
     voice_client_queue = list(bc.voice_client_queue)
     pos = 0
     for voice_queue_chunk in Msg.split_by_chunks(
             voice_client_queue, const.DISCORD_MAX_EMBED_FILEDS_COUNT):
         e = DiscordEmbed()
         e.title("🔊 Voice queue 🔊")
         e.color(0xcc1818)
         for entry in voice_queue_chunk:
             pos += 1
             e.add_field(
                 f"{entry.title}",
                 f"Position {pos} (YT: {entry.id}) requested by {entry.requested_by}"
             )
         await Msg.response(message, None, silent, embed=e.get())
示例#2
0
 async def _delrole(message, command, silent=False):
     """Unassign a role from the user
 Usage: !delrole @user role_name"""
     if not await Util.check_args_count(message, command, silent, min=3):
         return
     user = command[1]
     role_name = ' '.join(command[2:])
     role = discord.utils.get(message.guild.roles, name=role_name)
     if role is None:
         return null(await
                     Msg.response(message,
                                  f"Role '{role_name}' does not exist",
                                  silent))
     member = await message.guild.fetch_member(message.mentions[0].id)
     if member is None:
         return null(await
                     Msg.response(message, f"User '{user}' does not exist",
                                  silent))
     try:
         await member.remove_roles(role)
     except discord.HTTPException as e:
         return await null(
             Msg.response(
                 message,
                 f"Role '{role_name}' could not be assigned to user '{user}'. ERROR: '{e}'",
                 silent))
     await Msg.response(
         message,
         f"Successfully assigned role '{role_name}' to user '{user}'",
         silent)
示例#3
0
 async def _listreminder(message, command, silent=False):
     """Print list of reminders
 Examples:
     !listreminder
     !listreminder 5 <- prints only first 5 reminders"""
     if not await Util.check_args_count(
             message, command, silent, min=1, max=2):
         return
     if len(command) == 2:
         count = await Util.parse_int(
             message, command[1],
             f"Second parameter for '{command[0]}' should be amount of reminders to print",
             silent)
         if count is None:
             return
         reminders_count = count
     else:
         reminders_count = len(bc.config.reminders)
     reminder_list = []
     for index, reminder in bc.config.reminders.items():
         rep = f' (repeats every {reminder.repeat_after} {reminder.repeat_interval_measure})'
         prereminders = f' ({", ".join([str(x) + " min" for x in reminder.prereminders_list])} prereminders enabled)'
         reminder_list.append((
             reminder.time, reminder.message, f"{index} at {reminder.time} "
             f"{f' in <#{reminder.channel_id}>' if message.channel.id != reminder.channel_id else ''}"
             f"{rep if reminder.repeat_after else ''}"
             f"{prereminders if reminder.prereminders_list else ''}"))
     reminder_list.sort()
     reminder_list = reminder_list[:reminders_count]
     embed_color = random.randint(0x000000, 0xffffff)
     for reminder_chunk in Msg.split_by_chunks(
             reminder_list, const.DISCORD_MAX_EMBED_FILEDS_COUNT):
         e = DiscordEmbed()
         e.title("List of reminders")
         e.color(embed_color)
         for rem in reminder_chunk:
             e.add_field(rem[1], rem[2])
         await Msg.response(message, None, silent, embed=e.get())
示例#4
0
 async def run(self, message, command, user, silent=False):
     if len(inspect.stack(0)) >= const.MAX_SUBCOMMAND_DEPTH:
         return null(await message.channel.send(
             "ERROR: Maximum subcommand depth is reached!"))
     log.debug(f"Processing command: {message.content}")
     channel_id = message.channel.id
     if isinstance(
             message.channel,
             discord.Thread):  # Inherit command permissions for threads
         channel_id = message.channel.parent_id
     if not self.is_available(channel_id):
         return null(await message.channel.send(
             f"Command '{command[0]}' is not available in this channel"))
     if user is not None and self.permission > user.permission_level:
         return null(await message.channel.send(
             f"You don't have permission to call command '{command[0]}'"))
     self.times_called += 1
     postpone_execution = [
         "addcmd",
         "updcmd",
         "addextcmd",
         "updextcmd",
         "addbgevent",
         "addresponse",
         "updresponse",
     ]
     if message.content.split(' ')[0][1:] not in postpone_execution:
         log.debug2(f"Command (before processing): {message.content}")
         message.content = await self.process_subcommands(
             message.content, message, user)
         log.debug2(
             f"Command (after processing subcommands): {message.content}")
     else:
         log.debug2("Subcommands are not processed!")
     command = message.content[1:].split(' ')
     command = list(filter(None, command))
     if self.perform is not None:
         return await self.get_actor()(message, command, silent)
     elif self.message is not None:
         response = self.message
         log.debug2(f"Command (before processing): {response}")
         response = await self.process_variables(response, message, command)
         log.debug2(f"Command (after processing variables): {response}")
         response = await self.process_subcommands(response, message, user)
         log.debug2(f"Command (after processing subcommands): {response}")
         if response:
             if not silent:
                 if len(response) > const.DISCORD_MAX_MESSAGE_LENGTH * 5:
                     await message.channel.send(
                         "ERROR: Max message length exceeded "
                         f"({len(response)} > {const.DISCORD_MAX_MESSAGE_LENGTH * 5})"
                     )
                 elif len(const.UNICODE_EMOJI_REGEX.findall(response)) > 50:
                     await message.channel.send(
                         "ERROR: Max amount of Unicode emojis for one message exceeded "
                         f"({len(const.UNICODE_EMOJI_REGEX.findall(response))} > {50})"
                     )
                 else:
                     for chunk in Msg.split_by_chunks(
                             response, const.DISCORD_MAX_MESSAGE_LENGTH):
                         await message.channel.send(chunk)
             return response
     elif self.cmd_line is not None:
         cmd_line = self.cmd_line[:]
         log.debug2(f"Command (before processing): {cmd_line}")
         cmd_line = await self.process_variables(cmd_line,
                                                 message,
                                                 command,
                                                 safe=True)
         log.debug2(f"Command (after processing variables): {cmd_line}")
         cmd_line = await self.process_subcommands(cmd_line,
                                                   message,
                                                   user,
                                                   safe=True)
         log.debug2(f"Command (after processing subcommands): {cmd_line}")
         return await Util.run_external_command(message, cmd_line, silent)
     else:
         await message.channel.send(
             f"Command '{command[0]}' is not callable")