From 484d230a7f76ce0d85f4f514974151f119412f4a Mon Sep 17 00:00:00 2001 From: Spuds <46386050+Spuds1224@users.noreply.github.com> Date: Thu, 24 Aug 2023 02:16:35 -0400 Subject: [PATCH 01/13] Revert "feat: added watermark detection for embeded links" --- .gitignore | 3 -- .vscode/launch.json | 16 +++++++ cogs/listener.py | 103 ++++++++++++++++++-------------------------- logging.conf | 36 ---------------- main.py | 37 +++++----------- requirements.txt | 3 -- 6 files changed, 68 insertions(+), 130 deletions(-) create mode 100644 .vscode/launch.json delete mode 100644 logging.conf diff --git a/.gitignore b/.gitignore index ae154bb..ede60c9 100644 --- a/.gitignore +++ b/.gitignore @@ -176,7 +176,6 @@ cython_debug/ actions-runner .vscode/* -.vscode !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json @@ -188,5 +187,3 @@ actions-runner # Built Visual Studio Code Extensions *.vsix - -log.txt \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2e20100 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "main.py", + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/cogs/listener.py b/cogs/listener.py index b17628a..abd4d0f 100644 --- a/cogs/listener.py +++ b/cogs/listener.py @@ -1,81 +1,60 @@ -#listener.py -import logging -from typing import Union - -import cv2 -import discord import numpy as np -import requests +import cv2 from discord.ext import commands - -# makes a filter for logs -class DebugFilter(logging.Filter): - def filter(self, record): - return not record.levelno == logging.DEBUG - class IFunnyDetector(commands.Cog): def __init__(self, bot): self.bot = bot - def image_checker(self, file:Union[discord.Attachment, discord.message.Message]) -> bool: - """Takes an attachment or a message as an argument and returns a bool based on weather it is an image or not - - Args: - attachment (discord.Attachment | discord.message.Message): Either an attachment or a link. - """ - match type(file): - case discord.message.Attachment: - if str(file.content_type)[0:5] =="image": - return True - else: - return False - case discord.message.Message: - if (file.content[-4:] == ".jpg" or file.content[-4:] == ".png") and file.content[0:8] == "https://": # does it start with https and end with .jpg or .png? - return True - else: - return False - case _: - return False + # # function to hadle embedded links as well as real images + # def watermark_detector(image_url = None, attachment = None): + # if image_url is None and attachment is None: + # return None + # else: + # # gets image and makes it grayscale + # if attachment is not None: + # image = await attachment.read() - # function to handle embedded links as well as real images - def watermark_detector(self, image: Union[discord.Attachment, str]): - match type(image): - case discord.message.Attachment: - image_bytes = image.read() - case discord.message.Message: - response = requests.get(image.content) - image_bytes = response.content - case _: - raise Exception("Invalid parameter!") + # arr = np.fromstring(og_img, dtype=np.uint8) + # img = cv2.imdecode(arr, -1) # 'Load it as it is' https://stackoverflow.com/questions/21061814/how-can-i-read-an-image-from-an-internet-url-in-python-cv2-scikit-image-and-mah - arr = np.fromstring(string=image_bytes, dtype=np.uint8) - img = cv2.imdecode(arr, -1) # 'Load it as it is' https://stackoverflow.com/questions/21061814/how-can-i-read-an-image-from-an-internet-url-in-python-cv2-scikit-image-and-mah + # # compares the picture with the ifunny watermark + # img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # http://www.learningaboutelectronics.com/Articles/How-to-match-an-image-embedded-in-another-image-Python-OpenCV.php + # template = cv2.imread("ifunny_watermark.jpg", 0) + # result = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF_NORMED) - # compares the picture with the ifunny watermark - img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # http://www.learningaboutelectronics.com/Articles/How-to-match-an-image-embedded-in-another-image-Python-OpenCV.php - template = cv2.imread("ifunny_watermark.jpg", 0) - result = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF_NORMED) - - # determines if the ifunny watermark is in the image - min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) - if min_val < 0.01: # found this code from google ai - return True - else: - return False + # # determines if the ifunny watermark is in the image + # min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) + # if min_val < 0.01: # found this code from google ai + # return True + # else: + # return False @commands.Cog.listener() async def on_message(self, message): # gets the url to every attachment in the message if message.attachments != []: - for attachment in message.attachments: - if self.image_checker(attachment): # is it a valid image? - if self.watermark_detector(attachment): # does it have the watermark? - await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") - else: - if self.image_checker(message): # is it a valid image? - if self.watermark_detector(message): # does it have the watermark? + for i in message.attachments: + try: + # gets image and makes it grayscale + og_img = await i.read() + arr = np.fromstring(og_img, dtype=np.uint8) + img = cv2.imdecode(arr, -1) # 'Load it as it is' https://stackoverflow.com/questions/21061814/how-can-i-read-an-image-from-an-internet-url-in-python-cv2-scikit-image-and-mah + + # compares the picture with the ifunny watermark + img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # http://www.learningaboutelectronics.com/Articles/How-to-match-an-image-embedded-in-another-image-Python-OpenCV.php + template = cv2.imread("ifunny_watermark.jpg", 0) + result = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF_NORMED) + + # determines if the ifunny watermark is in the image + min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) + if min_val < 0.01: # found this code from google ai await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") + except cv2.error: + pass + + + def setup(bot): # this is called by Pycord to setup the cog bot.add_cog(IFunnyDetector(bot)) # add the cog to the bot \ No newline at end of file diff --git a/logging.conf b/logging.conf deleted file mode 100644 index 395ad42..0000000 --- a/logging.conf +++ /dev/null @@ -1,36 +0,0 @@ -[loggers] -keys=root,defaultLogger - -[handlers] -keys=consoleHandler, fileHandler - -[formatters] -keys=simpleFormatter, timeFormatter - -[logger_root] -level=INFO -handlers=consoleHandler - -[logger_defaultLogger] -level=INFO -handlers=consoleHandler, fileHandler -qualname=defaultLogger -propagate=0 - -[handler_consoleHandler] -class=StreamHandler -level=DEBUG -formatter=simpleFormatter -args=(sys.stdout,) - -[handler_fileHandler] -class=FileHandler -level=DEBUG -formatter=timeFormatter -args=('%(logfilename)s',) - -[formatter_simpleFormatter] -format=%(levelname)s - %(message)s - -[formatter_timeFormatter] -format=%(asctime)s - %(name)s - %(levelname)s - %(message)s \ No newline at end of file diff --git a/main.py b/main.py index b05e794..88d8d2b 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,5 @@ # main.py -import logging -import logging.config -import os - -import discord - -# sets up logging -logging.config.fileConfig('logging.conf', defaults={'logfilename': '/home/pi/Bot_Data/ifunny_crusader/log.txt'}) -logger = logging.getLogger("defaultLogger") - -# logs when the bot starts -logger.info(f"Program started!") +import discord, os # gets bot token from env BOT_TOKEN = os.getenv("BOT_TOKEN") @@ -23,27 +12,23 @@ @bot.event # prints when the bot has connected to discord async def on_connect(): - logger.info(f'{bot.user} has connected to Discord!') + print (f'\n{bot.user} has connected to Discord!') # loads the commands - extensions_loaded = bot.load_extension('cogs.listener', store=True) - if extensions_loaded["cogs.listener"] == True: # type: ignore - logger.info("Listener Cog Loaded!") - else: - logger.error("Listener Cog not loaded!") + bot.load_extension('cogs.listener') + # await bot.sync_commands() # prints what guilds the bot is connected to @bot.event async def on_ready(): await bot.wait_until_ready() - guild_strings = [f"{guild.name} (id:{guild.id})\n" async for guild in bot.fetch_guilds(limit=None)] - logger.info(f"Logged in as {bot.user} ID: {bot.user.id}") # type: ignore - logger.info(f"{bot.user} has connected to the following guild(s):\n {''.join(guild_strings)}") + print( + f'Logged in as {bot.user} ID: {bot.user.id}\n{bot.user} has connected to the following guild(s):\n' + ) + async for guild in bot.fetch_guilds(limit=None): + print (f'{guild.name} (id: {guild.id})') # runs the bot bot.run(BOT_TOKEN) -# main bot invite url -# https://discord.com/api/oauth2/authorize?client_id=1141155606963683442&permissions=274877908992&scope=bot - -# dev bot invite url -# https://discord.com/api/oauth2/authorize?client_id=1144056108747595897&permissions=274877908992&scope=bot \ No newline at end of file +# invite url +# https://discord.com/api/oauth2/authorize?client_id=1141155606963683442&permissions=274877908992&scope=bot \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 260abae..8040c9e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ aiohttp==3.8.5 aiosignal==1.3.1 async-timeout==4.0.3 attrs==23.1.0 -certifi==2023.7.22 charset-normalizer==3.2.0 frozenlist==1.4.0 idna==3.4 @@ -10,6 +9,4 @@ multidict==6.0.4 numpy==1.25.2 opencv-python==4.8.0.76 py-cord==2.4.1 -requests==2.31.0 -urllib3==2.0.4 yarl==1.9.2 From 43439e0499453c866249a5f1dfc642f012efbc6e Mon Sep 17 00:00:00 2001 From: Spuds <46386050+Spuds1224@users.noreply.github.com> Date: Thu, 24 Aug 2023 02:37:53 -0400 Subject: [PATCH 02/13] Revert "Revert "feat: added watermark detection for embeded links"" --- .gitignore | 3 ++ .vscode/launch.json | 16 ------- cogs/listener.py | 103 ++++++++++++++++++++++++++------------------ logging.conf | 36 ++++++++++++++++ main.py | 37 +++++++++++----- requirements.txt | 3 ++ 6 files changed, 130 insertions(+), 68 deletions(-) delete mode 100644 .vscode/launch.json create mode 100644 logging.conf diff --git a/.gitignore b/.gitignore index ede60c9..ae154bb 100644 --- a/.gitignore +++ b/.gitignore @@ -176,6 +176,7 @@ cython_debug/ actions-runner .vscode/* +.vscode !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json @@ -187,3 +188,5 @@ actions-runner # Built Visual Studio Code Extensions *.vsix + +log.txt \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 2e20100..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "main.py", - "console": "integratedTerminal", - "justMyCode": true - } - ] -} \ No newline at end of file diff --git a/cogs/listener.py b/cogs/listener.py index abd4d0f..b17628a 100644 --- a/cogs/listener.py +++ b/cogs/listener.py @@ -1,60 +1,81 @@ -import numpy as np +#listener.py +import logging +from typing import Union + import cv2 +import discord +import numpy as np +import requests from discord.ext import commands + +# makes a filter for logs +class DebugFilter(logging.Filter): + def filter(self, record): + return not record.levelno == logging.DEBUG + class IFunnyDetector(commands.Cog): def __init__(self, bot): self.bot = bot - # # function to hadle embedded links as well as real images - # def watermark_detector(image_url = None, attachment = None): - # if image_url is None and attachment is None: - # return None - # else: - # # gets image and makes it grayscale - # if attachment is not None: - # image = await attachment.read() + def image_checker(self, file:Union[discord.Attachment, discord.message.Message]) -> bool: + """Takes an attachment or a message as an argument and returns a bool based on weather it is an image or not + + Args: + attachment (discord.Attachment | discord.message.Message): Either an attachment or a link. + """ + match type(file): + case discord.message.Attachment: + if str(file.content_type)[0:5] =="image": + return True + else: + return False + case discord.message.Message: + if (file.content[-4:] == ".jpg" or file.content[-4:] == ".png") and file.content[0:8] == "https://": # does it start with https and end with .jpg or .png? + return True + else: + return False + case _: + return False - # arr = np.fromstring(og_img, dtype=np.uint8) - # img = cv2.imdecode(arr, -1) # 'Load it as it is' https://stackoverflow.com/questions/21061814/how-can-i-read-an-image-from-an-internet-url-in-python-cv2-scikit-image-and-mah + # function to handle embedded links as well as real images + def watermark_detector(self, image: Union[discord.Attachment, str]): + match type(image): + case discord.message.Attachment: + image_bytes = image.read() + case discord.message.Message: + response = requests.get(image.content) + image_bytes = response.content + case _: + raise Exception("Invalid parameter!") - # # compares the picture with the ifunny watermark - # img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # http://www.learningaboutelectronics.com/Articles/How-to-match-an-image-embedded-in-another-image-Python-OpenCV.php - # template = cv2.imread("ifunny_watermark.jpg", 0) - # result = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF_NORMED) + arr = np.fromstring(string=image_bytes, dtype=np.uint8) + img = cv2.imdecode(arr, -1) # 'Load it as it is' https://stackoverflow.com/questions/21061814/how-can-i-read-an-image-from-an-internet-url-in-python-cv2-scikit-image-and-mah - # # determines if the ifunny watermark is in the image - # min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) - # if min_val < 0.01: # found this code from google ai - # return True - # else: - # return False + # compares the picture with the ifunny watermark + img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # http://www.learningaboutelectronics.com/Articles/How-to-match-an-image-embedded-in-another-image-Python-OpenCV.php + template = cv2.imread("ifunny_watermark.jpg", 0) + result = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF_NORMED) + + # determines if the ifunny watermark is in the image + min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) + if min_val < 0.01: # found this code from google ai + return True + else: + return False @commands.Cog.listener() async def on_message(self, message): # gets the url to every attachment in the message if message.attachments != []: - for i in message.attachments: - try: - # gets image and makes it grayscale - og_img = await i.read() - arr = np.fromstring(og_img, dtype=np.uint8) - img = cv2.imdecode(arr, -1) # 'Load it as it is' https://stackoverflow.com/questions/21061814/how-can-i-read-an-image-from-an-internet-url-in-python-cv2-scikit-image-and-mah - - # compares the picture with the ifunny watermark - img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # http://www.learningaboutelectronics.com/Articles/How-to-match-an-image-embedded-in-another-image-Python-OpenCV.php - template = cv2.imread("ifunny_watermark.jpg", 0) - result = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF_NORMED) - - # determines if the ifunny watermark is in the image - min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) - if min_val < 0.01: # found this code from google ai + for attachment in message.attachments: + if self.image_checker(attachment): # is it a valid image? + if self.watermark_detector(attachment): # does it have the watermark? + await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") + else: + if self.image_checker(message): # is it a valid image? + if self.watermark_detector(message): # does it have the watermark? await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") - except cv2.error: - pass - - - def setup(bot): # this is called by Pycord to setup the cog bot.add_cog(IFunnyDetector(bot)) # add the cog to the bot \ No newline at end of file diff --git a/logging.conf b/logging.conf new file mode 100644 index 0000000..395ad42 --- /dev/null +++ b/logging.conf @@ -0,0 +1,36 @@ +[loggers] +keys=root,defaultLogger + +[handlers] +keys=consoleHandler, fileHandler + +[formatters] +keys=simpleFormatter, timeFormatter + +[logger_root] +level=INFO +handlers=consoleHandler + +[logger_defaultLogger] +level=INFO +handlers=consoleHandler, fileHandler +qualname=defaultLogger +propagate=0 + +[handler_consoleHandler] +class=StreamHandler +level=DEBUG +formatter=simpleFormatter +args=(sys.stdout,) + +[handler_fileHandler] +class=FileHandler +level=DEBUG +formatter=timeFormatter +args=('%(logfilename)s',) + +[formatter_simpleFormatter] +format=%(levelname)s - %(message)s + +[formatter_timeFormatter] +format=%(asctime)s - %(name)s - %(levelname)s - %(message)s \ No newline at end of file diff --git a/main.py b/main.py index 88d8d2b..b05e794 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,16 @@ # main.py -import discord, os +import logging +import logging.config +import os + +import discord + +# sets up logging +logging.config.fileConfig('logging.conf', defaults={'logfilename': '/home/pi/Bot_Data/ifunny_crusader/log.txt'}) +logger = logging.getLogger("defaultLogger") + +# logs when the bot starts +logger.info(f"Program started!") # gets bot token from env BOT_TOKEN = os.getenv("BOT_TOKEN") @@ -12,23 +23,27 @@ @bot.event # prints when the bot has connected to discord async def on_connect(): - print (f'\n{bot.user} has connected to Discord!') + logger.info(f'{bot.user} has connected to Discord!') # loads the commands - bot.load_extension('cogs.listener') - # await bot.sync_commands() + extensions_loaded = bot.load_extension('cogs.listener', store=True) + if extensions_loaded["cogs.listener"] == True: # type: ignore + logger.info("Listener Cog Loaded!") + else: + logger.error("Listener Cog not loaded!") # prints what guilds the bot is connected to @bot.event async def on_ready(): await bot.wait_until_ready() - print( - f'Logged in as {bot.user} ID: {bot.user.id}\n{bot.user} has connected to the following guild(s):\n' - ) - async for guild in bot.fetch_guilds(limit=None): - print (f'{guild.name} (id: {guild.id})') + guild_strings = [f"{guild.name} (id:{guild.id})\n" async for guild in bot.fetch_guilds(limit=None)] + logger.info(f"Logged in as {bot.user} ID: {bot.user.id}") # type: ignore + logger.info(f"{bot.user} has connected to the following guild(s):\n {''.join(guild_strings)}") # runs the bot bot.run(BOT_TOKEN) -# invite url -# https://discord.com/api/oauth2/authorize?client_id=1141155606963683442&permissions=274877908992&scope=bot \ No newline at end of file +# main bot invite url +# https://discord.com/api/oauth2/authorize?client_id=1141155606963683442&permissions=274877908992&scope=bot + +# dev bot invite url +# https://discord.com/api/oauth2/authorize?client_id=1144056108747595897&permissions=274877908992&scope=bot \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8040c9e..260abae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ aiohttp==3.8.5 aiosignal==1.3.1 async-timeout==4.0.3 attrs==23.1.0 +certifi==2023.7.22 charset-normalizer==3.2.0 frozenlist==1.4.0 idna==3.4 @@ -9,4 +10,6 @@ multidict==6.0.4 numpy==1.25.2 opencv-python==4.8.0.76 py-cord==2.4.1 +requests==2.31.0 +urllib3==2.0.4 yarl==1.9.2 From 476985bd0d8746e826cb854cfcdf37075f458053 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 03:44:01 -0400 Subject: [PATCH 03/13] fix: copying only the correct files to docker --- Dockerfile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8ad593b..0859e9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,5 +6,12 @@ RUN pip install -r requirements.txt RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y -COPY . . +COPY /cogs . +COPY /docker-compose.yml . +COPY /Dockerfile . +COPY /ifunny_watermark.jpg . +COPY /logging.conf . +COPY /main.py . +COPY /requirements.txt . + CMD [ "python3", "main.py" ] ["sudo", "/sbin/ldconfig -v"] \ No newline at end of file From a9fd3984c2da62fcc7c82afc0b5a37d5d9654611 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 03:46:23 -0400 Subject: [PATCH 04/13] fix: cogs not getting copied to the docker --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0859e9f..a9cf136 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN pip install -r requirements.txt RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y -COPY /cogs . +COPY /cogs/ . COPY /docker-compose.yml . COPY /Dockerfile . COPY /ifunny_watermark.jpg . From 60765f0e6f19f10cce3900a4afdb1dcda2c3c843 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 03:49:09 -0400 Subject: [PATCH 05/13] fix: another fix to the cogs in the docker --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a9cf136..f1fa279 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN pip install -r requirements.txt RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y -COPY /cogs/ . +ADD cogs . COPY /docker-compose.yml . COPY /Dockerfile . COPY /ifunny_watermark.jpg . From 5ee419e42bceccfb682679183fe94da77c63ca1d Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 04:06:20 -0400 Subject: [PATCH 06/13] fix: cog folder not copying --- Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index f1fa279..7420a4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,12 +6,12 @@ RUN pip install -r requirements.txt RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y -ADD cogs . -COPY /docker-compose.yml . -COPY /Dockerfile . -COPY /ifunny_watermark.jpg . -COPY /logging.conf . -COPY /main.py . -COPY /requirements.txt . +COPY /cogs/ /app/cogs/ +COPY docker-compose.yml /app/ +COPY Dockerfile /app/ +COPY ifunny_watermark.jpg /app/ +COPY logging.conf /app/ +COPY main.py /app/ +COPY requirements.txt /app/ CMD [ "python3", "main.py" ] ["sudo", "/sbin/ldconfig -v"] \ No newline at end of file From 903c6630b5b5c535c63e4406bf37f3a79a616287 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 04:18:35 -0400 Subject: [PATCH 07/13] fix: async issue breaking watermark detection --- cogs/listener.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cogs/listener.py b/cogs/listener.py index b17628a..92e2083 100644 --- a/cogs/listener.py +++ b/cogs/listener.py @@ -39,10 +39,10 @@ def image_checker(self, file:Union[discord.Attachment, discord.message.Message]) return False # function to handle embedded links as well as real images - def watermark_detector(self, image: Union[discord.Attachment, str]): + async def watermark_detector(self, image: Union[discord.Attachment, str]): match type(image): case discord.message.Attachment: - image_bytes = image.read() + image_bytes = await image.read() case discord.message.Message: response = requests.get(image.content) image_bytes = response.content @@ -70,11 +70,11 @@ async def on_message(self, message): if message.attachments != []: for attachment in message.attachments: if self.image_checker(attachment): # is it a valid image? - if self.watermark_detector(attachment): # does it have the watermark? + if await self.watermark_detector(attachment): # does it have the watermark? await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") else: if self.image_checker(message): # is it a valid image? - if self.watermark_detector(message): # does it have the watermark? + if await self.watermark_detector(message): # does it have the watermark? await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") def setup(bot): # this is called by Pycord to setup the cog From 6d18eff1e1bf0251cf48de89601795361cc08aae Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 20:07:24 -0400 Subject: [PATCH 08/13] fix: client secret not being read correctly --- .github/workflows/runner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index b7cbc54..64bb703 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -15,7 +15,7 @@ jobs: - name: Run Container run: sudo docker compose -f /home/pi/Bot_Data/ifunny_crusader/docker-compose.yml up -d --build env: - BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + TOKEN: ${{ secrets.TOKEN }} - name: Cleanup Unused Images run: sudo docker image prune -f \ No newline at end of file From 7443c17d3118ce20db6ca667d306b62b124be336 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 20:30:24 -0400 Subject: [PATCH 09/13] fix: bot not getting token from env --- Dockerfile | 2 -- docker-compose.yml | 2 +- main.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7420a4b..9cc4885 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,8 +7,6 @@ RUN pip install -r requirements.txt RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y COPY /cogs/ /app/cogs/ -COPY docker-compose.yml /app/ -COPY Dockerfile /app/ COPY ifunny_watermark.jpg /app/ COPY logging.conf /app/ COPY main.py /app/ diff --git a/docker-compose.yml b/docker-compose.yml index 0cc6396..c77671a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: build: . container_name: ifunny-crusader environment: - - BOT_TOKEN + - TOKEN restart: unless-stopped volumes: - /app/:/home/pi/Bot_Data/ifunny_crusader/ diff --git a/main.py b/main.py index b05e794..5c83db5 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ logger.info(f"Program started!") # gets bot token from env -BOT_TOKEN = os.getenv("BOT_TOKEN") +BOT_TOKEN = os.getenv("TOKEN") # defines the bot obj intents = discord.Intents.default() From eae918a81e2ec07e8344eda270ee6631601ed272 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 21:09:15 -0400 Subject: [PATCH 10/13] feat: switched to using github hosted runner --- .github/workflows/runner.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index 64bb703..1ea1246 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -6,7 +6,7 @@ on: jobs: run: - runs-on: self-hosted + runs-on: ubuntu-latest environment: production steps: @@ -15,7 +15,7 @@ jobs: - name: Run Container run: sudo docker compose -f /home/pi/Bot_Data/ifunny_crusader/docker-compose.yml up -d --build env: - TOKEN: ${{ secrets.TOKEN }} + BOT_TOKEN: ${{ secrets.TOKEN }} - name: Cleanup Unused Images run: sudo docker image prune -f \ No newline at end of file From fbb7ebe0333ed0141f698e550e6836382a7d6029 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 21:22:46 -0400 Subject: [PATCH 11/13] Revert "fix: async issue breaking watermark detection" This reverts commit 903c6630b5b5c535c63e4406bf37f3a79a616287. --- cogs/listener.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cogs/listener.py b/cogs/listener.py index 92e2083..b17628a 100644 --- a/cogs/listener.py +++ b/cogs/listener.py @@ -39,10 +39,10 @@ def image_checker(self, file:Union[discord.Attachment, discord.message.Message]) return False # function to handle embedded links as well as real images - async def watermark_detector(self, image: Union[discord.Attachment, str]): + def watermark_detector(self, image: Union[discord.Attachment, str]): match type(image): case discord.message.Attachment: - image_bytes = await image.read() + image_bytes = image.read() case discord.message.Message: response = requests.get(image.content) image_bytes = response.content @@ -70,11 +70,11 @@ async def on_message(self, message): if message.attachments != []: for attachment in message.attachments: if self.image_checker(attachment): # is it a valid image? - if await self.watermark_detector(attachment): # does it have the watermark? + if self.watermark_detector(attachment): # does it have the watermark? await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") else: if self.image_checker(message): # is it a valid image? - if await self.watermark_detector(message): # does it have the watermark? + if self.watermark_detector(message): # does it have the watermark? await message.reply("**IFUNNY DETECTED**\n**ANTI-CRINGE COUNTERMEASURES DEPLOYED**") def setup(bot): # this is called by Pycord to setup the cog From f2f636962d28ae353ebdd6f8f40b743a7abd136f Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 21:29:13 -0400 Subject: [PATCH 12/13] fix: runner not launching on push --- .github/workflows/runner.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index 1ea1246..748c4d9 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -6,14 +6,14 @@ on: jobs: run: - runs-on: ubuntu-latest + runs-on: self-hosted environment: production steps: - uses: actions/checkout@v3 - name: Run Container - run: sudo docker compose -f /home/pi/Bot_Data/ifunny_crusader/docker-compose.yml up -d --build + run: sudo docker compose up -d --build env: BOT_TOKEN: ${{ secrets.TOKEN }} From 0da31fa0dfeae5da94efec92459ecfd37cef3f76 Mon Sep 17 00:00:00 2001 From: Spuds1224 Date: Thu, 24 Aug 2023 21:32:36 -0400 Subject: [PATCH 13/13] fix: env had wrong var --- .github/workflows/runner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index 748c4d9..dd4230e 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -15,7 +15,7 @@ jobs: - name: Run Container run: sudo docker compose up -d --build env: - BOT_TOKEN: ${{ secrets.TOKEN }} + TOKEN: ${{ secrets.TOKEN }} - name: Cleanup Unused Images run: sudo docker image prune -f \ No newline at end of file