From 6c758297e7c67cec4c842d743199076d24eae976 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Tue, 12 Dec 2023 10:54:25 -0800 Subject: [PATCH] Making things cleaner, and fixing python formatter docker image --- Makefile | 2 +- app/bot.py | 46 +++++++++++++++------------------------------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 90b9d80b..ad28f84d 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include .env # https://github.com/psf/black/issues/1106#issuecomment-547230844 format: - docker run --rm -ti -v ${PWD}:/tmp/python/app python:alpine sh -c "apk add --no-cache gcc musl-dev; cd /tmp/python; pip install -q black; black ." + docker run --rm -ti -v ${PWD}:/tmp/python/app pyfound/black:latest_release sh -c "black /tmp/python" clean: docker rm -f dragon-bot-test diff --git a/app/bot.py b/app/bot.py index 75c84ac6..5213f1fe 100755 --- a/app/bot.py +++ b/app/bot.py @@ -115,38 +115,22 @@ async def convert_heic_to_jpg(ctx): @bot.listen("on_message") async def fix_social_media_links(ctx): - if "https://www.tiktok.com" in ctx.content: - await ctx.channel.send( - "%s said:\n%s" - % ( - ctx.author.mention, - ctx.content.replace("tiktok", "vxtiktok"), + correct_domains = { + "https://x.com": "vxtwitter", + "https://twitter.com": "vxtwitter", + "https://tiktok.com": "vxtiktok", + } + for k in correct_domains.keys(): + if k in ctx.content: + await ctx.channel.send( + "%s said:\n%s" + % ( + ctx.author.mention, + ctx.content.replace(k, "https://%s.com" % correct_domains[k]), + ) ) - ) - await ctx.delete() - return - - if "https://twitter.com" in ctx.content: - await ctx.channel.send( - "%s said:\n%s" - % ( - ctx.author.mention, - ctx.content.replace("twitter", "vxtwitter"), - ) - ) - await ctx.delete() - return - - if "https://x.com" in ctx.content: - await ctx.channel.send( - "%s said:\n%s" - % ( - ctx.author.mention, - ctx.content.replace("x", "vxtwitter"), - ) - ) - await ctx.delete() - return + await ctx.delete() + return @bot.event