diff --git a/Bot/Dockerfile b/Bot/Dockerfile new file mode 100644 index 0000000..da1cb43 --- /dev/null +++ b/Bot/Dockerfile @@ -0,0 +1,17 @@ +# syntax=docker/dockerfile:1 +FROM alpine:3.18.2 + +EXPOSE 8000 + +RUN mkdir /app && mkdir /app/data +WORKDIR /app + +COPY ./lynxie /app + +RUN apk update && \ + apk --no-cache add python3 py3-pip && \ + pip install --no-cache-dir -r requirements.txt \ + +RUN python3 database.py + +CMD ["python3", "main.py"] diff --git a/lynxie/assets/e621_blacklist.txt b/Bot/lynxie/assets/e621_blacklist.txt similarity index 57% rename from lynxie/assets/e621_blacklist.txt rename to Bot/lynxie/assets/e621_blacklist.txt index 23e42bc..a4c36c6 100644 --- a/lynxie/assets/e621_blacklist.txt +++ b/Bot/lynxie/assets/e621_blacklist.txt @@ -1,21 +1,27 @@ cub young +younger_penetrated teen teenager diaper pregnant +loli incest -father_and_son -father_and_daughter -mother_and_son -mother_and_daughter +parent_and_child +father_and_child +mother_and_child brother_and_sister sister_and_sister brother_and_brother +age-difference bestiality feral_and_anthro +human_on_feral +feral_on_human +anthro_on_feral +feral_on_anthro gore blood @@ -30,3 +36,4 @@ watersports urine snuff eating_feces +shota diff --git a/lynxie/assets/overlays/bandicam.png b/Bot/lynxie/assets/overlays/bandicam.png similarity index 100% rename from lynxie/assets/overlays/bandicam.png rename to Bot/lynxie/assets/overlays/bandicam.png diff --git a/lynxie/assets/overlays/bubble.png b/Bot/lynxie/assets/overlays/bubble.png similarity index 100% rename from lynxie/assets/overlays/bubble.png rename to Bot/lynxie/assets/overlays/bubble.png diff --git a/lynxie/assets/overlays/gang.png b/Bot/lynxie/assets/overlays/gang.png similarity index 100% rename from lynxie/assets/overlays/gang.png rename to Bot/lynxie/assets/overlays/gang.png diff --git a/lynxie/assets/overlays/jerm-a.png b/Bot/lynxie/assets/overlays/jerm-a.png similarity index 100% rename from lynxie/assets/overlays/jerm-a.png rename to Bot/lynxie/assets/overlays/jerm-a.png diff --git a/lynxie/assets/overlays/jerma.png b/Bot/lynxie/assets/overlays/jerma.png similarity index 100% rename from lynxie/assets/overlays/jerma.png rename to Bot/lynxie/assets/overlays/jerma.png diff --git a/lynxie/assets/overlays/liveleak.png b/Bot/lynxie/assets/overlays/liveleak.png similarity index 100% rename from lynxie/assets/overlays/liveleak.png rename to Bot/lynxie/assets/overlays/liveleak.png diff --git a/lynxie/commands/__init__.py b/Bot/lynxie/commands/__init__.py similarity index 100% rename from lynxie/commands/__init__.py rename to Bot/lynxie/commands/__init__.py diff --git a/lynxie/commands/animals.py b/Bot/lynxie/commands/animals.py similarity index 100% rename from lynxie/commands/animals.py rename to Bot/lynxie/commands/animals.py diff --git a/lynxie/commands/e621.py b/Bot/lynxie/commands/e621.py similarity index 58% rename from lynxie/commands/e621.py rename to Bot/lynxie/commands/e621.py index ce6f1a4..7905108 100644 --- a/lynxie/commands/e621.py +++ b/Bot/lynxie/commands/e621.py @@ -9,7 +9,6 @@ from lynxie.config import E621_API_KEY, E621_USERNAME, E621_BLACKLIST from lynxie.utils import error_message -_E621_API_URL = "https://e621.net/" _E621_AUTH = f"{E621_USERNAME}:{E621_API_KEY}".encode("utf-8") _E621_API_HEADERS = { "Accept": "application/json", @@ -25,8 +24,7 @@ class E621(commands.Cog): @commands.command() async def porb(self, ctx, *tags): - # Base url for the request - url = _E621_API_URL + "posts.json/?limit=1&tags=order:random+rating:e+" + url = "https://e621.net/posts.json/?limit=1&tags=order:random+rating:e+" caught_tags = [] for tag in tags: @@ -41,7 +39,8 @@ class E621(commands.Cog): if caught_tags: error = ( "An error occurred while fetching the image! " - f"{', '.join(caught_tags)} is a blacklisted tag!" + f"{', '.join(['`'+tag+'`' for tag in caught_tags])} " + f"is a blacklisted tag!" ) await ctx.reply(embed=error_message(error)) return @@ -49,6 +48,13 @@ class E621(commands.Cog): request = requests.get(url, headers=_E621_API_HEADERS) response = json.loads(request.text) + if request.status_code == 503: + error = ( + "The bot is currently rate limited! " + "Wait a while before trying again." + ) + await ctx.reply(embed=error_message(error)) + return if request.status_code != 200: error = ( "An error occurred while fetching the image! " @@ -58,44 +64,51 @@ class E621(commands.Cog): return if not response["posts"]: - error = "No results found for the given tags! " f"(Tags: {', '.join(tags)})" + tags_to_display = range(min(len(tags), 20)) + error = ( + "No results found for the given tags! " + f"(Tags: {', '.join(['`'+tags[i]+'`' for i in tags_to_display])})" + ) await ctx.reply(embed=error_message(error)) return + post = response["posts"][0] + general_tags = post["tags"]["general"] + embed = discord.Embed( title="E621", - description=response["posts"][0]["description"] - or "No description provided.", + description=post["description"] or "No description provided.", colour=discord.Colour.orange(), ) embed.add_field( name="Score", - value=f"^ {response['posts'][0]['score']['up']} | " - f"v {response['posts'][0]['score']['down']}", + value=f"⬆️ {post['score']['up']} | ⬇️ {post['score']['down']}", ) embed.add_field( name="Favorites", - value=response["posts"][0]["fav_count"], + value=post["fav_count"], + ) + embed.add_field( + name="Comments", + value=post["comment_count"], ) embed.add_field( - name="Source", - value=", ".join(response["posts"][0]["sources"]) or "No source provided.", + name="Source(s)", + value=", ".join(post["sources"]) or "No source provided.", inline=False, ) embed.add_field( name="Tags", - value=", ".join(response["posts"][0]["tags"]["general"]) - or "No tags provided.", + value=( + ", ".join(["`"+general_tags[i]+"`" for i in range(min(len(general_tags), 20))]) + or "No tags provided." + ), inline=False, ) - embed.set_footer( - text=f"ID: {response['posts'][0]['id']} | " - f"Created: {response['posts'][0]['created_at']}" - ) - - embed.set_image(url=response["posts"][0]["file"]["url"]) + embed.set_footer(text=f"ID: {post['id']} | Created: {post['created_at']}") + embed.set_image(url=post["file"]["url"]) await ctx.reply(embed=embed) diff --git a/lynxie/commands/hello.py b/Bot/lynxie/commands/hello.py similarity index 100% rename from lynxie/commands/hello.py rename to Bot/lynxie/commands/hello.py diff --git a/lynxie/commands/help.py b/Bot/lynxie/commands/help.py similarity index 100% rename from lynxie/commands/help.py rename to Bot/lynxie/commands/help.py diff --git a/lynxie/commands/image.py b/Bot/lynxie/commands/image.py similarity index 95% rename from lynxie/commands/image.py rename to Bot/lynxie/commands/image.py index 10410d8..8e022a5 100644 --- a/lynxie/commands/image.py +++ b/Bot/lynxie/commands/image.py @@ -16,9 +16,10 @@ class Img(commands.Cog): self.bot = bot @staticmethod - async def get_image_attachments(ctx): + async def get_image_attachments(ctx) -> discord.Attachment or None: if ctx.message.attachments: return ctx.message.attachments[0] + if ctx.message.reference: if ctx.message.reference.resolved.attachments: return ctx.message.reference.resolved.attachments[0] @@ -27,15 +28,17 @@ class Img(commands.Cog): and ctx.message.reference.resolved.embeds[0].image ): return ctx.message.reference.resolved.embeds[0].image - elif ctx.message.embeds and ctx.message.embeds[0].image: + + if ctx.message.embeds and ctx.message.embeds[0].image: return ctx.message.embeds[0].image - else: - channel = ctx.guild.get_channel(ctx.channel.id) - async for message in channel.history(limit=10): - if message.attachments: - return message.attachments[0] - if message.embeds and message.embeds[0].image: - return message.embeds[0].image + + channel = ctx.guild.get_channel(ctx.channel.id) + async for message in channel.history(limit=10): + if message.attachments: + return message.attachments[0] + + if message.embeds and message.embeds[0].image: + return message.embeds[0].image return None diff --git a/lynxie/commands/music.py b/Bot/lynxie/commands/music.py similarity index 100% rename from lynxie/commands/music.py rename to Bot/lynxie/commands/music.py diff --git a/lynxie/commands/ping.py b/Bot/lynxie/commands/ping.py similarity index 100% rename from lynxie/commands/ping.py rename to Bot/lynxie/commands/ping.py diff --git a/lynxie/config.py b/Bot/lynxie/config.py similarity index 84% rename from lynxie/config.py rename to Bot/lynxie/config.py index 79e28bd..8497e8c 100644 --- a/lynxie/config.py +++ b/Bot/lynxie/config.py @@ -1,4 +1,5 @@ import os +import re import requests import dotenv from discord import Object @@ -14,8 +15,9 @@ DISCORD_TOKEN = ( DISCORD_GUILD_ID = Object(id=1040757387033849976) LYNXIE_PREFIX = "?" -DATA_PATH = os.path.join("lynxie", "data") -ASSETS_PATH = os.path.join("lynxie", "assets") +DATA_PATH = os.path.join("/app", "data") +ASSETS_PATH = os.path.join("/app", "assets") + DATABASE_URI = "sqlite:///" + os.path.join(DATA_PATH, "lynxie.db") @@ -74,3 +76,12 @@ with open(os.path.join(ASSETS_PATH, "e621_blacklist.txt"), "r") as file: for line in file.readlines(): if word := line.strip(): E621_BLACKLIST.add(word) + + +BAD_WORDS = [] +_bad_words_request = requests.get( + "https://raw.githubusercontent.com/mogade/badwords/master/en.txt" +) +for word in _bad_words_request.text.split("\n"): + if word := word.strip(): + BAD_WORDS.append(re.compile(word, re.IGNORECASE)) diff --git a/lynxie/database.py b/Bot/lynxie/database.py similarity index 100% rename from lynxie/database.py rename to Bot/lynxie/database.py diff --git a/lynxie/__main__.py b/Bot/lynxie/main.py similarity index 92% rename from lynxie/__main__.py rename to Bot/lynxie/main.py index 1b99648..dfe9ce0 100644 --- a/lynxie/__main__.py +++ b/Bot/lynxie/main.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python3 +# vim: set fileencoding=utf-8 : + import asyncio import discord @@ -43,7 +46,11 @@ async def on_command(ctx): @lynxie.event async def on_command_error(ctx, error): + if isinstance(error, commands.CommandNotFound): + return + print(error) + error = "An internal error occurred while processing your command, oopsie..." await ctx.reply(embed=error_message(error), delete_after=5) diff --git a/lynxie/utils.py b/Bot/lynxie/utils.py similarity index 100% rename from lynxie/utils.py rename to Bot/lynxie/utils.py diff --git a/Bot/requirements.txt b/Bot/requirements.txt new file mode 100644 index 0000000..8d7af93 --- /dev/null +++ b/Bot/requirements.txt @@ -0,0 +1,13 @@ +python +discord +black +sqlalchemy +python-dotenv +discord-py +requests +beautifulsoup4 +selenium +webdriver-manager +flask +yt-dlp +pillow diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f31a525 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.9" + +services: + bot: + build: Bot + restart: unless-stopped + volumes: + - ./Bot/data:/app/data + environment: + DISCORD_TOKEN: ${DISCORD_TOKEN} + DISCORD_GUILD_ID: ${DISCORD_GUILD_ID} + E621_USERNAME: ${E621_USERNAME} + E621_API_KEY: ${E621_API_KEY} diff --git a/lynxie/__init__.py b/lynxie/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/lynxie/data/.gitignore b/lynxie/data/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/lynxie/data/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore