async def on_guild_join(self, guild: discord.Guild): """Called when the bot joins a guild (server).""" log.info( "Nab Bot added to server: {0.name} (ID: {0.id})".format(guild)) message = f"**I've been added to this server.**\n" \ f"Some things you should know:\n" \ f"‣ My command prefix is: `{config.command_prefix[0]}` (it is customizable)\n" \ f"‣ You can see all my commands with: `{config.command_prefix[0]}help` or " \ f"`{config.command_prefix[0]}commands`\n" \ f"‣ You can configure me using: `{config.command_prefix[0]}settings`\n" \ f"‣ You can set a world for me to track by using `{config.command_prefix[0]}settings world`\n" \ f"‣ If you want a logging channel, create a channel named `{config.log_channel_name}`\n" \ f"‣ If you need help, join my support server: **<https://discord.me/NabBot>**\n" \ f"‣ For more information and links in: `{config.command_prefix[0]}about`" for member in guild.members: if member.id in self.members: self.members[member.id].append(guild.id) else: self.members[member.id] = [guild.id] try: channel = self.get_top_channel(guild) if channel is None: log.warning( f"Could not send join message on server: {guild.name}. No allowed channel found." ) return await channel.send(message) except discord.HTTPException as e: log.error(f"Could not send join message on server: {guild.name}.", exc_info=e)
async def on_command_error(self, ctx: context.NabCtx, error): """Handles command errors""" if isinstance(error, commands.errors.CommandNotFound): return elif isinstance(error, commands.NoPrivateMessage): await ctx.send(error) elif isinstance(error, commands.CommandInvokeError): log.error(f"Exception in command: {ctx.message.clean_content}", exc_info=error.original) if isinstance(error.original, discord.HTTPException): await ctx.send("Sorry, the message was too long to send.") else: if ctx.bot_permissions.embed_links: embed = discord.Embed(colour=discord.Colour(0xff1414)) embed.set_author(name="Support Server", url="https://discord.gg/NmDvhpY", icon_url=self.user.avatar_url) embed.set_footer( text="Please report this bug in the support server.") embed.add_field( name=f"{ctx.tick(False)}Command Error", value= f"```py\n{error.original.__class__.__name__}: {error.original}```", inline=False) await ctx.send(embed=embed) else: await ctx.send( f'{ctx.tick(False)} Command error:\n```py\n{error.original.__class__.__name__}:' f'{error.original}```')
async def wait_for_confirmation_reaction( self, ctx: Context, message: Message, timeout: float = 120) -> Optional[bool]: """Waits for the command author (ctx.author) to reply with a Y or N reaction Returns True if the user reacted with Y Returns False if the user reacted with N Returns None if the user didn't react at all""" YES_REACTION = '\U0001f1fe' NO_REACTION = '\U0001f1f3' try: await message.add_reaction(YES_REACTION) await message.add_reaction(NO_REACTION) except discord.Forbidden: log.error( "wait_for_confirmation_reaction: No permission to add reactions." ) return None def check_react(reaction: Reaction, user: User): if reaction.message.id != message.id: return False if user.id != ctx.author.id: return False if reaction.emoji not in [NO_REACTION, YES_REACTION]: return False return True try: react = await self.wait_for("reaction_add", timeout=timeout, check=check_react) if react[0].emoji == NO_REACTION: return False except asyncio.TimeoutError: return None finally: if not is_private(ctx.channel): try: await message.clear_reactions() except: pass return True
async def on_command_error(self, ctx: Context, error): """Handles command errors""" if isinstance(error, commands.errors.CommandNotFound): return elif isinstance(error, commands.NoPrivateMessage): await ctx.send("This command cannot be used in private messages.") elif isinstance(error, commands.CommandInvokeError): if isinstance(error.original, discord.HTTPException): log.error( f"Reply to '{ctx.message.clean_content}' was too long.") await ctx.send("Sorry, the message was too long to send.") return log.error(f"Exception in command: {ctx.command.qualified_name}", exc_info=error.original) # Bot returns error message on discord if an owner called the command if ctx.message.author.id in config.owner_ids: await ctx.send('```Py\n{0.__class__.__name__}: {0}```'.format( error.original))
) quit() token = get_token() print("Loading cogs...") for cog in initial_cogs: try: nabbot.load_extension(cog) print(f"Cog {cog} loaded successfully.") except Exception as e: print(f'Cog {cog} failed to load:') traceback.print_exc(limit=-1) for extra in config.extra_cogs: try: nabbot.load_extension(extra) print(f"Extra cog {extra} loaded successfully.") except Exception as e: print(f'Extra og {extra} failed to load:') traceback.print_exc(limit=-1) try: print("Attempting login...") nabbot.run(token) except discord.errors.LoginFailure: print("Invalid token. Edit token.txt to fix it.") input("\nPress any key to continue...") quit() log.error("NabBot crashed")
login = getLogin() try: token = login.token except NameError: token = "" try: email = login.email password = login.password except NameError: email = "" password = "" try: if token: bot.run(token) elif email and password: bot.run(login.email, login.password) else: print("Dados de login não encontrados. Edite ou delete o arquivo login.py e reinicie.") input("\nAperte qualquer tecla para continuar...") quit() except discord.errors.LoginFailure: print("Dados de login incorretos. Edite ou delete login.py e reinicie.") input("\nAperte qualquer tecla para continuar...") quit() finally: bot.session.close() log.error("Monkey Slave crashed")
'Other': Image.open("./images/Other.png"), 'NoValue': Image.open("./images/NoValue.png"), 'Unknown': Image.open("./images/Unknown.png") } scan_speed = [0.035] * 10 MIN_HEIGHT = 27 # Images with a width MIN_WIDTH = 34 # or height smaller than this are not considered. Pixel = Tuple[int, ...] if os.path.isfile(LOOTDB): lootDatabase = sqlite3.connect(LOOTDB) lootDatabase.row_factory = dict_factory else: log.error("Could not find loot.db") exit() class LootScanException(commands.CommandError): pass class Loot: def __init__(self, bot: NabBot): self.bot = bot self.processing_users = [] @commands.group(invoke_without_command=True, case_insensitive=True) async def loot(self, ctx: NabCtx): """Scans an image of a container looking for Tibia items and shows an approximate loot value.