def on_server_join(self, server): server_count = util.get_server_count() if server_count % 25 == 0: # Announce every 100 servers (for now) yield from util.say( gconf.announcement_channel, ":confetti_ball: I'm on __**%d SERVERS**__ now!!!1111" % server_count) util.logger.info("Joined server name: %s id: %s", server.name, server.id) yield from util.set_up_roles(server) server_stats = self.server_stats(server) yield from util.duelogger.info( ("DueUtil has joined the server **" + util.ultra_escape_string(server.name) + "**!\n" + "``Member count →`` " + str(server_stats["member_count"]) + "\n" + "``Bot members →``" + str(server_stats["bot_count"]) + "\n" + ("**BOT SERVER**" if server_stats["bot_server"] else ""))) # Message to help out new server admins. yield from self.send_message( server.default_channel, ":wave: __Thanks for adding me!__\n" + "If you would like to customize me to fit your " + "server take a quick look at the admins " + "guide at <https://dueutil.tech/howto/#adming>.\n" + "It shows how to change the command prefix here, and set which " + "channels I or my commands can be used in (along with a bunch of other stuff)." ) # Update stats yield from servercounts.update_server_count(self)
def on_server_join(self, server): server_count = util.get_server_count() if server_count % 10000 == 0: # Announce every 100 servers (for now) yield from util.say( gconf.announcement_channel, ":confetti_ball: I'm on __**%d SERVERS**__ now!!!1111" % server_count) yield from util.set_up_roles(server) server_stats = self.server_stats(server) if random.randint(1, 3) == 2: util.logger.info("Joined server name: %s id: %s", server.name, server.id) yield from util.duelogger.info( ("DueUtil has joined the server **" + util.ultra_escape_string(server.name) + "**!\n" + "``Member count →`` " + str(server_stats["member_count"]) + "\n" + "``Bot members →``" + str(server_stats["bot_count"]) + "\n" + ("**BOT SERVER**" if server_stats["bot_server"] else ""))) # Message to help out new server admins. yield from self.send_message( server.owner, ":wave: __Thanks for adding me!__\n" + "If you would like to customize me to fit your " + "server take a quick look at the admin " + "guide at <https://dueutil.weebly.com/theelgirlsdueutil.html>.\n" + "It shows how to change the command prefix here, and set which " + "channels I or my commands can be used in (along with a bunch of other stuff).\n" + "If you still need help, you can use ``!requestsupport cnf``, and a support person will join your server as soon as they can for in-person help!" ) dbltoken = "" url = "https://top.gg/api/bots/" + "496480755728384002" + "/stats" headers = {"Authorization": dbltoken} payload = {"server_count": util.get_server_count()} requests.post(url, data=json.dumps(payload), headers=headers)
def on_error(self, event, *args): ctx = args[0] if len(args) == 1 else None ctx_is_message = isinstance(ctx, discord.Message) error = sys.exc_info()[1] if ctx is None: yield from util.duelogger.error( ("**DueUtil experienced an error!**\n" + "__Stack trace:__ ```" + traceback.format_exc() + "```")) util.logger.error("None message/command error: %s", error) elif isinstance(error, util.DueUtilException): # A normal dueutil user error if error.channel is not None: yield from self.send_message(error.channel, error.get_message()) else: yield from self.send_message(ctx.channel, error.get_message()) return elif isinstance(error, util.DueReloadException): loader.reload_modules() yield from util.say(error.channel, loader.get_loaded_modules()) return elif isinstance(error, discord.errors.Forbidden): if ctx_is_message: channel = ctx.channel if isinstance(error, util.SendMessagePermMissing): util.logger.warning( "Missing send permissions in channel %s (%s)", channel.name, channel.id) else: try: # Attempt to warn user yield from util.say( channel, "The action could not be performed as I'm **missing permissions**!" ) except util.SendMessagePermMissing: pass # They've block sending messages too. return elif isinstance(error, discord.HTTPException): util.logger.error("Discord HTTP error: %s", error) elif isinstance(error, aiohttp.errors.ClientResponseError): if ctx_is_message: util.logger.error("%s: ctx from %s: %s", error, ctx.author.id, ctx.content) else: util.logger.error(error) elif isinstance(error, RuntimeError) and ERROR_OF_DEATH in str(error): util.logger.critical( "Something went very wrong and the error of death came for us: %s", error) os._exit(1) elif ctx_is_message: yield from self.send_message( ctx.channel, (":bangbang: **Something went wrong...**")) trigger_message = discord.Embed(title="Trigger", type="rich", color=gconf.DUE_COLOUR) trigger_message.add_field(name="Message", value=ctx.author.mention + ":\n" + ctx.content) yield from util.duelogger.error( ("**Message/command triggred error!**\n" + "__Stack trace:__ ```" + traceback.format_exc()[-1500:] + "```"), embed=trigger_message) # Log exception on sentry. util.sentry_client.captureException() traceback.print_exc()
def on_error(self, event, *args): ctx = args[0] if len(args) == 1 else None ctx_is_message = isinstance(ctx, discord.Message) error = sys.exc_info()[1] if ctx is None: yield from util.duelogger.error( ("**DueUtil experienced an error!**\n" + "__Stack trace:__ ```" + traceback.format_exc() + "```")) util.logger.error("None message/command error: %s", error) elif isinstance(error, util.DueUtilException): # A normal dueutil user error if error.channel is not None: yield from self.send_message(error.channel, error.get_message()) else: yield from self.send_message(ctx.channel, error.get_message()) return elif isinstance(error, util.DueReloadException): loader.reload_modules() yield from util.say(error.channel, loader.get_loaded_modules()) return elif isinstance(error, discord.errors.Forbidden): if ctx_is_message: channel = ctx.channel server = ctx.server if isinstance(error, util.SendMessagePermMissing): util.logger.warning( "Missing send permissions in channel %s (%s/%s)", channel.name, server.id, channel.id) else: try: # Attempt to warn user perms = ctx.server.me.permissions_in(ctx.channel) yield from util.say( ctx.channel, "The action could not be performed as I'm **missing permissions**! Make sure I have the following permissions:\n" + "- Manage Roles %s\n" % (":white_check_mark:" if perms.manage_roles else ":x:") + "- Embed links %s\n" % (":white_check_mark:" if perms.embed_links else ":x:") + "- Attach files %s\n" % (":white_check_mark:" if perms.attach_files else ":x:") + "- Read Message History %s\n" % (":white_check_mark:" if perms.read_message_history else ":x:") + "- Use external emojis %s\n" % (":white_check_mark:" if perms.external_emojis else ":x:") + "- Add reactions%s" % (":white_check_mark:" if perms.add_reactions else ":x:")) except util.SendMessagePermMissing: pass # They've block sending messages too. return elif isinstance(error, discord.HTTPException): util.logger.error("Discord HTTP error: %s", error) elif isinstance(error, aiohttp.errors.ClientResponseError): if ctx_is_message: util.logger.error("%s: ctx from %s: %s", error, ctx.author.id, ctx.content) else: util.logger.error(error) elif isinstance(error, RuntimeError) and ERROR_OF_DEATH in str(error): util.logger.critical( "Something went very wrong and the error of death came for us: %s", error) os._exit(1) elif ctx_is_message: # yield from self.send_message(ctx.channel, (":bangbang: **Something went wrong. The error is most likely related to a new update, so the dev will fix it as soon as she wakes up!**")) trigger_message = discord.Embed(title="Trigger", type="rich", color=gconf.DUE_COLOUR) trigger_message.add_field(name="Message", value=ctx.author.mention + ":\n" + ctx.content + "\n" + ctx.server.id + "-" + ctx.channel.id) yield from util.duelogger.error( ("**Message/command triggred error!**\n" + "__Stack trace:__ ```" + traceback.format_exc()[-1500:] + "```"), embed=trigger_message) # Log exception on sentry. util.sentry_client.captureException() traceback.print_exc()