async def warning_count(self, ctx, member: discord.Member): """ Shows count of all warnings from member. """ count = await self.bot.api_client.get_member_warnings_count(member.id) warnings_embed = thumbnail(f"Warnings: {count}", member, "Warning count") await ctx.send(embed=warnings_embed)
async def _suggestion_helper(self, ctx, message_id: int, reason: str, status: constants.SuggestionStatus): """ Helper for suggestion approve/deny. :param ctx: context where approve/deny command was called. :param message_id: suggestion message id :param reason: reason for approving/denying :param status: either constants.SuggestionStatus.approved or constants.SuggestionStatus.denied :return: """ msg: Message = await self.user_suggestions_channel.fetch_message( message_id) if msg is None: return await ctx.send( embed=failure("Suggestion message not found."), delete_after=10) elif not msg.embeds or not msg.embeds[0].fields: return await ctx.send( embed=failure("Message is not in correct format."), delete_after=10) api_data = await self.bot.api_client.get_suggestion(message_id) msg_embed = msg.embeds[0] if status == constants.SuggestionStatus.denied: field_title = "Reason" state = "denied" msg_embed.colour = Color.red() else: field_title = "Comment" state = "approved" msg_embed.colour = Color.green() dm_embed_msg = ( f"Your suggestion[[link]]({msg.jump_url}) was **{state}**:\n" f"```\"{api_data['brief'][:200]}\"```\n" f"\nReason:\n{reason}") dm_embed = thumbnail(dm_embed_msg, member=ctx.me, title=f"Suggestion {state}.") msg_embed.set_field_at(0, name="Status", value=status.value) if len(msg_embed.fields) == 1: msg_embed.add_field(name=field_title, value=reason, inline=True) else: msg_embed.set_field_at(1, name=field_title, value=reason, inline=True) await self.bot.api_client.edit_suggestion(message_id, status, reason) await msg.edit(embed=msg_embed) await self._dm_member(api_data["author_id"], dm_embed)
async def send(self, data: dict): """ Makes the bot send requested message channel or user or both. :param data: dict in format { "channel_id": 123, "user_id": 123, "message": "Test" } Where both channel_id and user_id are optional but at least one has to be passed. Message is the message to send. """ message = data.get("message") if message is None: raise EndpointBadArguments() channel_id = data.get("channel_id") user_id = data.get("user_id") if channel_id is None and user_id is None: raise EndpointBadArguments() channel = self.bot.get_channel(channel_id) user = self.bot.get_user(user_id) if channel is None and user is None: raise DiscordIDNotFound() if channel is not None: await channel.send(embed=thumbnail(message, self.bot.user)) if user is not None: try: await user.send(embed=thumbnail(message, self.bot.user, "A message just for you!")) except Forbidden: logger.info( f"Skipping send endpoint to {user} as he blocked DMs.")
async def show_warnings(self, ctx, member: discord.Member): """Shows all warnings of member.""" warnings = await self.bot.api_client.get_member_warnings(member.id) if not warnings: await ctx.send(embed=info("No warnings.", ctx.me)) for count, sub_dict in enumerate(warnings): formatted_warnings = [f"{key}:{value}" for key, value in sub_dict.items()] warnings_msg = "\n".join(formatted_warnings) # TODO temporal quick fix for possible too long message, to fix when embed navigation is done warnings_msg = warnings_msg[:1900] warnings_embed = thumbnail(warnings_msg, member, f"Warning #{count+1}") await ctx.send(embed=warnings_embed)
async def show_warnings(self, ctx, member: discord.Member): """ Shows all warnings of member. """ warnings = await self.bot.api_client.get_member_warnings(member.id) for sub_dict in warnings: formatted_warnings = [ f"{key}:{value}" for key, value in sub_dict.items() ] warnings_msg = "\n".join(formatted_warnings) # TODO temporal quick fix for possible too long message, to fix when embed navigation is done warnings_msg = warnings_msg[:1900] warnings_embed = thumbnail(warnings_msg, member, "Listing warnings") await ctx.send(embed=warnings_embed)