def guide(self, event, guide_name): if self.config.guides.get(guide_name, "no-guide") == "no-guide": event.msg.reply( ":no_entry_sign: couldn't find that guide. use `+guide list` to find guides." ) return Pages.create_new(self.bot, "guide", event, page=1, guide=guide_name)
def load(self, ctx): super().load(ctx) Pages.register("guide", self.initialize_page, self.update_page) if not os.path.isfile("experiments.json"): self.experiments = {"dm-guide-on-join": 25} return with open("experiments.json", "r") as experiments: # if this errors, dabbit didn't do the config right. self.experiments = json.loads(experiments.readline())
def load(self, ctx): super().load(ctx) self.client = MongoClient(self.config.mongodb_host, self.config.mongodb_port, username=self.config.mongodb_username, password=self.config.mongodb_password) self.database = self.client.get_database("experience") self.users = self.database.get_collection("users") self.actions = self.database.get_collection("actions") self.purchases = self.database.get_collection("purchases") Pages.register("xp_store", self.initialize_pages, self.update_page)
def on_reaction(self, event): if event.user_id == self.bot.client.state.me.id: return if event.emoji.name == Pages.prev_emoji: Pages.update(self.bot, event.channel_id, event.message_id, "PREV", event.user_id) elif event.emoji.name == Pages.next_emoji: Pages.update(self.bot, event.channel_id, event.message_id, "NEXT", event.user_id)
def guide(self, event, guide_name): if self.config.guides.get(guide_name, "no-guide") == "no-guide": event.msg.reply( f":no_entry_sign: I couldn't find that guide. Try picking one from the list instead. You can call up this list at any time using `+guide list`." ) self.list_guides(event) return Pages.create_new(self.bot, "guide", event.channel, event.msg, page=1, guide=guide_name)
def on_reaction(self, event): if event.user_id == self.bot.client.state.me.id: return message = self.bot.client.api.channels_messages_get( event.channel_id, event.message_id) if event.emoji.name == Pages.prev_emoji: if Pages.update(message, "PREV", event.user_id): self.bot.client.api.channels_messages_reactions_delete( event.channel_id, event.message_id, Pages.prev_emoji, event.user_id) elif event.emoji.name == Pages.next_emoji: if Pages.update(message, "NEXT", event.user_id): self.bot.client.api.channels_messages_reactions_delete( event.channel_id, event.message_id, Pages.next_emoji, event.user_id)
def guide_send(self, event): randnum = random.random() time.sleep(30) if randnum <= self.experiments["dm-guide-on-join"]: try: channel = event.member.user.open_dm() Pages.create_new(self.bot, "guide", channel, page=1, guide="guide", is_join_dm=True) log_to_bot_log( self.bot, ":green_book: Guide was successfully sent to {user}.". format(user=str(event.member))) except: log_to_bot_log( self.bot, ":no_entry_sign: {user} has DMs disabled, so the guide wasn't sent to them." .format(user=str(event.member)))
def gen_participants_pages(self): info = "" point_count = dict() for rid, report in self.reported_cards.items(): user = str(report["author_id"]) if not user in point_count.keys(): point_count[user] = 0 if report["status"] == "Approved": point_count[user] += self.config.boards[report["board"]]["points"] for participant_id, name in self.participants.items(): info += f"{name} (`{participant_id}`: {point_count[participant_id] if participant_id in point_count else 0})\n" return Pages.paginate(info)
def handle_exception(event, bot, exception): # catch everything and extract all info we can from the func arguments so we see what exactly was going on print("Exception caught, extracting information") print("====EXCEPTION====") print(exception) print("====STACKTRACE====") print(traceback.format_exc()) print("====ORIGINAL MESSAGE====") print(event.msg.content) print("====SENDER====") print(event.msg.author) print("====Channel====") print("{} ({})".format(event.msg.channel.name, event.msg.channel.id)) embed = MessageEmbed() embed.title = "Exception caught" embed.add_field(name="Original message", value=Utils.trim_message(event.msg.content, 1024)) embed.add_field(name="Channel", value="{} ({})".format(event.msg.channel.name, event.msg.channel.id)) embed.add_field(name="Sender", value=str(event.msg.author)) embed.add_field(name="Exception", value=str(exception)) parts = Pages.paginate(str(traceback.format_exc()), max_chars=1024) if len(parts) > 4: embed.add_field( name="Stacktrace", value= "Something went incredibly wrong, stacktrace is over 4096 chars!") else: for part in parts: embed.add_field(name="Stacktrace", value=part) embed.timestamp = datetime.utcnow().isoformat() embed.color = int('ff0000', 16) log_to_bot_log(bot, embed=embed)
def unload(self, ctx): super().unload(ctx) Pages.unregister("guide")
def update_participants(self, message, page_num, action, data): pages = self.gen_participants_pages() page, page_num = Pages.basic_pages(pages, page_num, action) return None, self.gen_participants_embed(page, page_num + 1, len(pages)), page_num
def event_participants(self, event): Pages.create_new(self.bot, "participants", event.channel, event.msg)
def store(self, event): Pages.create_new(self.bot, "xp_store", event)
def load(self, ctx): super().load(ctx) Pages.load_from_disc()
def load(self, ctx): super(GuidePlugin, self).load(ctx) Pages.register("guide", self.initialize_page, self.update_page)
def unload(self, ctx): Pages.unregister("guide") super(GuidePlugin, self).unload(ctx)
def load(self, ctx): super().load(ctx) self.load_event_stats() Pages.register("participants", self.init_participants, self.update_participants)
def unload(self, ctx): super().unload(ctx) self.save_event_stats() Pages.unregister("participants")
def unload(self, ctx): super().unload(ctx) Pages.save_to_disc()
def store(self, event): Pages.create_new(self.bot, "xp_store", event.channel, event.msg)
def gen_participants_pages(self): info = "" for participant_id, name in self.participants.items(): info += "{} (`{}`)\n".format(name, participant_id) return Pages.paginate(info)