コード例 #1
0
 async def on_message_delete(self, message):
     if message.guild is None:
         return
     SUBJECT_ID = self.get_current_subject()
     SQLFunctions.update_statistics(message.author,
                                    SUBJECT_ID,
                                    messages_deleted=1)
コード例 #2
0
    async def on_message_edit(self, before, message):
        # Adds the edited message to the table
        if message.guild is None:
            return

        # gets the char difference between the two messages
        b_cont = before.content
        a_cont = message.content
        before_char_count = len(b_cont)
        before_word_count = len(b_cont.split(" "))
        before_emoji_count = b_cont.count(":") // 2
        before_spoiler_count = b_cont.count("||") // 2
        after_char_count = len(a_cont)
        after_word_count = len(a_cont.split(" "))
        after_emoji_count = a_cont.count(":") // 2
        after_spoiler_count = a_cont.count("||") // 2

        SUBJECT_ID = self.get_current_subject()
        SQLFunctions.update_statistics(
            message.author,
            SUBJECT_ID,
            messages_edited=1,
            characters_sent=after_char_count - before_char_count,
            words_sent=after_word_count - before_word_count,
            emojis_sent=after_emoji_count - before_emoji_count,
            spoilers_sent=after_spoiler_count - before_spoiler_count)
コード例 #3
0
 async def on_reaction_remove(self, reaction, member):
     if reaction.message.guild is None or member.bot:
         return
     if member.id == reaction.message.author.id:
         return
     SUBJECT_ID = self.get_current_subject()
     SQLFunctions.update_statistics(member, SUBJECT_ID, reactions_removed=1)
     SQLFunctions.update_statistics(reaction.message.author,
                                    SUBJECT_ID,
                                    reactions_taken_away=1)
コード例 #4
0
 async def on_reaction_add(self, reaction, member):
     if reaction.message.guild is None or member.bot:
         return
     if member.id == reaction.message.author.id:
         return
     SUBJECT_ID = self.get_current_subject()
     SQLFunctions.update_statistics(
         member, SUBJECT_ID,
         reactions_added=1)  # reactions added by the user
     SQLFunctions.update_statistics(
         reaction.message.author, SUBJECT_ID,
         reactions_received=1)  # reactions received by the user
コード例 #5
0
    async def on_message(self, message):
        # only count stats in servers
        if message.guild is None:
            return
        # deletes the message if its in #newcomers
        if message.channel.id == 815881148307210260 and not message.author.bot:
            try:
                await message.delete()
                deleted_messages = SQLFunctions.get_config(
                    "deleted_messages", self.conn)
                if len(deleted_messages) == 0:
                    deleted_messages = 0
                else:
                    deleted_messages = deleted_messages[0]
                SQLFunctions.insert_or_update_config("deleted_messages",
                                                     deleted_messages + 1,
                                                     self.conn)
            except discord.NotFound:  # message was already deleted
                pass
        SUBJECT_ID = self.get_current_subject()
        # Makes it better to work with the message
        msg = demojize(message.content)

        char_count = len(msg)
        word_count = len(msg.split(" "))
        emoji_count = msg.count(":") // 2
        spoiler_count = msg.count("||") // 2

        # File Statistics
        files_amount = len(message.attachments)
        file_sizes = 0
        images_amt = 0
        for f in message.attachments:
            file_sizes += f.size
            if f.height is not None and f.height > 0:
                images_amt += 1

        SQLFunctions.update_statistics(message.author,
                                       SUBJECT_ID,
                                       conn=self.conn,
                                       messages_sent=1,
                                       characters_sent=char_count,
                                       words_sent=word_count,
                                       spoilers_sent=spoiler_count,
                                       emojis_sent=emoji_count,
                                       files_sent=files_amount,
                                       file_size_sent=file_sizes,
                                       images_sent=images_amt)