Пример #1
0
 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)
Пример #2
0
 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())
Пример #3
0
 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)
Пример #4
0
    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)
Пример #5
0
 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)
Пример #6
0
    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)
Пример #7
0
 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)))
Пример #8
0
 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)
Пример #9
0
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)
Пример #10
0
 def unload(self, ctx):
     super().unload(ctx)
     Pages.unregister("guide")
Пример #11
0
 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
Пример #12
0
 def event_participants(self, event):
     Pages.create_new(self.bot, "participants", event.channel, event.msg)
Пример #13
0
 def store(self, event):
     Pages.create_new(self.bot, "xp_store", event)
Пример #14
0
 def load(self, ctx):
     super().load(ctx)
     Pages.load_from_disc()
Пример #15
0
 def load(self, ctx):
     super(GuidePlugin, self).load(ctx)
     Pages.register("guide", self.initialize_page, self.update_page)
Пример #16
0
 def unload(self, ctx):
     Pages.unregister("guide")
     super(GuidePlugin, self).unload(ctx)
Пример #17
0
 def load(self, ctx):
     super().load(ctx)
     self.load_event_stats()
     Pages.register("participants", self.init_participants, self.update_participants)
Пример #18
0
 def unload(self, ctx):
     super().unload(ctx)
     self.save_event_stats()
     Pages.unregister("participants")
Пример #19
0
 def unload(self, ctx):
     super().unload(ctx)
     Pages.save_to_disc()
Пример #20
0
 def store(self, event):
     Pages.create_new(self.bot, "xp_store", event.channel, event.msg)
Пример #21
0
 def gen_participants_pages(self):
     info = ""
     for participant_id, name in self.participants.items():
         info += "{} (`{}`)\n".format(name, participant_id)
     return Pages.paginate(info)