async def rolls(self, ctx: commands.Context, maximum: int): """Set the maximum number of dice a user can roll at one time. WARNING: Setting this too high will allow other users to slow down/freeze/crash your bot! Generating random numbers is easily the most CPU consuming process here, so keep this number low (less than one million, and way less than that on a Pi) """ action = "is already set at" if maximum == await self.config.max_dice_rolls(): pass elif maximum > 1000000: action = "has been left at" pred = MessagePredicate.yes_or_no(ctx) await ctx.send( question(( "Are you **sure** you want to set the maximum rolls to {}? (yes/no)\n" "Setting this over one million will allow other users to " "slow down/freeze/crash your bot!".format(maximum)))) try: await ctx.bot.wait_for("message", check=pred, timeout=30) except asyncio.TimeoutError: pass if pred.result: await self.config.max_dice_rolls.set(maximum) action = "is now set to" else: pass else: await self.config.max_dice_rolls.set(maximum) action = "is now set to" await ctx.send( checkmark("Maximum dice rolls per user {} {}".format( action, await self.config.max_dice_rolls())))
async def _user_report( self, ctx: commands.Context, image_proof_url: str, do_imgur_upload: bool, member: Union[discord.Member, int], ban_message: str, ): """Perform user report.""" description = "" sent = [] is_error = False config_services = await self.config.guild(ctx.guild).services() if isinstance(member, discord.Member): member_id = member.id member_avatar_url = member.avatar_url else: member_id = member member_avatar_url = None # Gather services that can have reports sent to them report_services = [] for service_name, service_config in config_services.items(): if not service_config.get("enabled", False): continue # This service is not enabled service_class = self.all_supported_services.get(service_name, None) if not service_class: continue # This service is not supported try: service_class().report except AttributeError: continue # This service does not support reporting api_key = await self.get_api_key(service_name, config_services) if not api_key: continue # This service needs an API key set to work report_services.append((service_class(), api_key)) # Send error if there are no services to send to if not report_services: await self.send_embed( ctx, self.embed_maker( "Error", discord.Colour.red(), "No services have been set up. Please check `[p]bancheckset service settings` for more details.", member_avatar_url, ), ) return # Upload to Imgur if needed if do_imgur_upload: service_keys = await self.bot.get_shared_api_tokens("imgur") imgur_client_id = service_keys.get("client_id", False) if not imgur_client_id: await ctx.send( error( "This command requires that you have an Imgur Client ID. Please set one with `.imgurcreds`." ) ) return image_proof_url = await Imgur.upload(image_proof_url, imgur_client_id) if not image_proof_url: await ctx.send( error( "Uploading image to Imgur failed. Ban report has not been sent." ) ) return # Ask if the user really wants to do this pred = MessagePredicate.yes_or_no(ctx) await ctx.send( question( f"Are you **sure** you want to send this ban report for **{member}**? (yes/no)" ) ) try: await ctx.bot.wait_for("message", check=pred, timeout=30) except asyncio.TimeoutError: pass if pred.result: pass else: await ctx.send(error("Sending ban report has been canceled.")) return # Send report to services for report_service_tuple in report_services: response = await report_service_tuple[0].report( member_id, report_service_tuple[1], ctx.author.id, ban_message, image_proof_url, ) sent.append(response.service) if response.result and response.reason: description += checkmark( f"**{response.service}:** Sent ({response.reason})\n" ) elif response.result: description += checkmark(f"**{response.service}:** Sent\n") else: is_error = True description += error( f"**{response.service}:** Failure ({response.reason if response.reason else 'No reason given'})\n" ) # Generate results if is_error: await self.send_embed( ctx, self.embed_maker( f"Errors occurred while sending reports for **{member}**", discord.Colour.red(), description, member_avatar_url, ), ) else: await self.send_embed( ctx, self.embed_maker( f"Reports sent for **{member}**", discord.Colour.green(), f"Services: {', '.join(sent)}", member_avatar_url, ), )
async def _user_report( self, ctx: commands.Context, image_proof_url: str, do_imgur_upload: bool, member: Union[discord.Member, int], ban_message: str, ): """Perform user report.""" description = "" sent = [] is_error = False config_services = await self.config.guild(ctx.guild).services() for service_name, service_config in config_services.items(): if not service_config.get("enabled", False): continue service_class = self.all_supported_services.get( service_name, False) if not service_class: continue api_key = await self.get_api_key(service_name, config_services) if not api_key: continue try: service_class().report except AttributeError: continue # This service does not support reporting if do_imgur_upload: service_keys = await self.bot.get_shared_api_tokens("imgur") imgur_client_id = service_keys.get("client_id", False) if not imgur_client_id: await ctx.send( error( "This command requires that you have an Imgur Client ID. Please set one with `.imgurcreds`." )) return image_proof_url = await Imgur.upload(image_proof_url, imgur_client_id) if not image_proof_url: await ctx.send( error( "Uploading image to Imgur failed. Ban report has not been sent." )) return pred = MessagePredicate.yes_or_no(ctx) await ctx.send( question( "Are you **sure** you want to send this ban report for **{}**? (yes/no)" .format(member))) try: await ctx.bot.wait_for("message", check=pred, timeout=30) except asyncio.TimeoutError: pass if pred.result: pass else: await ctx.send(error("Sending ban report has been canceled.")) return if isinstance(member, discord.Member): member_id = member.id member_avatar_url = member.avatar_url else: member_id = member member_avatar_url = None response = await service_class().report(member_id, api_key, ctx.author.id, ban_message, image_proof_url) sent.append(response.service) if response.result and response.reason: description += "**{}:** Sent ({})\n".format( response.service, response.reason) elif response.result: description += "**{}:** Sent\n".format(response.service) elif not response.result and response.reason: is_error = True description += "**{}:** Failure ({})\n".format( response.service, response.reason) else: is_error = True description += "**{}:** Failure (HTTP error {})\n".format( response.service, response.http_status) if is_error: await self.send_embed( ctx.channel, self.embed_maker( "Errors occured while sending reports for **{}**".format( member), discord.Colour.red(), description, member_avatar_url, ), ) elif not sent: await self.send_embed( ctx.channel, self.embed_maker( "Error", discord.Colour.red(), "No services have been set up. Please check `[p]bancheckset` for more details.", member_avatar_url, ), ) else: await self.send_embed( ctx.channel, self.embed_maker( "Reports sent for **{}**".format(member), discord.Colour.green(), "Services: {}".format(", ".join(sent)), member_avatar_url, ), )