Beispiel #1
0
    def __init__(self, bot):
        self.bot = bot
        self.cancel_all = False
        self.cancel_draws = []
        self.pause_draws = False
        self.progress = {}
        self.image = None
        self.queue = []
        self.background_draw.start()
        self.db_path = "./data/discord.db"
        self.place_path = "./place/"
        self.conn = SQLFunctions.connect()

        self.LINE_HEIGHT = 62  # amount of lines which fit on the place canvas
        self.CHAR_WIDTH = 166  # amount of chars which fit in a line on the place canvas
        self.font = ImageFont.truetype("./data/nk57-monospace-cd-rg.ttf", 12)
        self.userToCopyTextFrom = -1
        self.last_line = SQLFunctions.get_config("Draw_Last_Line", self.conn)
        if len(self.last_line) == 0:
            self.last_line = 0
        else:
            self.last_line = self.last_line[0]
        self.last_char = SQLFunctions.get_config("Draw_Last_Char", self.conn)
        if len(self.last_char) == 0:
            self.last_char = 0
        else:
            self.last_char = self.last_char[0]
Beispiel #2
0
    async def background_draw(self):
        await self.bot.wait_until_ready()
        # opens and readies all the files
        imgs = self.get_all_queues(self.place_path)
        for im in imgs:
            if im.fp not in self.progress:
                start = SQLFunctions.get_config(f"Start_{im.fp}", self.conn)
                if len(start) == 0:
                    start = 0
                else:
                    start = start[0]
                self.progress[im.fp] = {
                    "count": start,
                    "img": im,
                    "queue": im.get_queue()
                }
                self.queue.append({
                    "ID": im.fp,
                    "size": im.size,
                    "img": im,
                    "queue": im.get_queue()
                })

        channelID = SQLFunctions.get_config("PlaceChannel", self.conn)
        if len(channelID) == 0:
            channelID = 819966095070330950
        else:
            channelID = channelID[0]
        channel = self.bot.get_channel(channelID)
        if channel is None:
            channel = self.bot.get_channel(402551175272202252)  # fallback test channel

        # keeps going through all lists
        while len(self.queue) > 0 and not self.pause_draws:
            drawing = self.queue[0]
            start = SQLFunctions.get_config(f"Start_{drawing['ID']}", self.conn)
            end = SQLFunctions.get_config(f"End_{drawing['ID']}", self.conn)
            if len(start) == 0:
                start = 0
            else:
                start = start[0]
            if len(end) == 0:
                end = drawing["img"].size
            else:
                end = end[0]
            done = await self.draw_pixels(drawing["ID"], channel, start, end)
            if done:
                self.remove_drawing(drawing["ID"])
Beispiel #3
0
 def __init__(self, bot):
     self.bot = bot
     self.send_message_to_finn = False
     self.lecture_updater_version = "v1.0"
     self.db_path = "./data/discord.db"
     self.conn = SQLFunctions.connect()
     self.channel_to_post = SQLFunctions.get_config(
         "channel_to_post_updates", self.conn)
     self.background_loop.start()
     self.current_activity = ""
     self.sent_updates = {
         1: False,
         2: False,
         3: False,
         4: False,
         5: False,
         6: False
     }
     self.lecture_updates_role_ids = {
         "first": 885810281358446623,
         "second": 885810349121622056,
         "third": 885810401969831978
     }
     self.sent_advent = False
     self.sent_website_updates = False
Beispiel #4
0
 def __init__(self, bot):
     self.bot = bot
     self.clap_counter = 0
     self.time = 0
     self.confirmed_cases = 0
     self.confirm_msg = None  # Confirmed message
     self.conn = SQLFunctions.connect()
     self.time_since_task_start = time.time()
     self.background_check_cases.start()
     self.sent_covid = False
     recent_covid_cases = SQLFunctions.get_config("COVID_Cases", self.conn)
     recent_covid_day = SQLFunctions.get_config("COVID_Day", self.conn)
     if len(recent_covid_cases) > 0:
         self.cases_today = recent_covid_cases[0]
     else:
         self.cases_today = 0
     if len(recent_covid_day) > 0:
         self.last_cases_day = recent_covid_day[0]
     else:
         self.last_cases_day = 0
Beispiel #5
0
    def __init__(self, bot):
        self.bot = bot
        self.db_path = "./data/discord.db"
        self.conn = SQLFunctions.connect()

        # gets the button value to watch
        self.watch_button_value = SQLFunctions.get_config("ButtonValue", self.conn)
        if len(self.watch_button_value) == 0:
            self.watch_button_value = 1e6
        else:
            self.watch_button_value = self.watch_button_value[0]
        self.sent_message = False
        self.old_value = 1e6  # to ignore fake buttons we store the last value
Beispiel #6
0
 def __init__(self, bot):
     self.bot = bot
     self.newcomers = {}
     self.ta_request = {}
     self.bot_prefix_path = "./data/bot_prefix.json"
     with open(self.bot_prefix_path, "r") as f:
         self.all_prefix = json.load(f)
     self.db_path = "./data/discord.db"
     self.conn = SQLFunctions.connect()
     self.welcome_message_id = SQLFunctions.get_config(
         "WelcomeMessage", self.conn)
     self.requested_help = [
     ]  # list of DiscordUserIDs of who requested help
     self.requested_ta = [
     ]  # list of DiscordUserIDs which requested TA role to avoid spam
Beispiel #7
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)