From 4989f51b2450cff8dc984f85034fdb10627b01ca Mon Sep 17 00:00:00 2001 From: Matt C Date: Tue, 21 Dec 2021 19:50:35 -0500 Subject: [PATCH] more trimming --- combo.py => bot.py | 5 --- cogs/debug.py | 8 ---- cogs/internet.py | 11 ------ requirements.txt | 3 +- util_functions.py | 98 ---------------------------------------------- 5 files changed, 2 insertions(+), 123 deletions(-) rename combo.py => bot.py (94%) diff --git a/combo.py b/bot.py similarity index 94% rename from combo.py rename to bot.py index 01c46a8..b636706 100644 --- a/combo.py +++ b/bot.py @@ -17,22 +17,17 @@ from discord.ext import commands from pretty_help import DefaultMenu, PrettyHelp # Other pip packages -from PIL import Image, ImageDraw, ImageFont -from better_profanity import profanity import asyncio import requests # My own classes n such from global_config import configboi from util_functions import * -from server_config import serverconfig if os.path.sep == "\\": print("This bot is only supported on UNIX-like systems. Aborting.") sys.exit(1) -sconf = serverconfig() - intents = discord.Intents.default() intents.members = True diff --git a/cogs/debug.py b/cogs/debug.py index 3700f34..2597201 100644 --- a/cogs/debug.py +++ b/cogs/debug.py @@ -3,7 +3,6 @@ from discord.ext import commands from util_functions import * from global_config import configboi -from server_config import serverconfig # Hopefully we'll never need logging here @@ -14,13 +13,6 @@ class Debug(commands.Cog): def __init__(self, bot): self.bot = bot self.confmgr = configboi("config.txt", False) - self.sconf = serverconfig() - - @commands.command() - async def resetgd(self, ctx): - if ctx.message.author.id == ctx.message.guild.owner_id: - self.sconf.rs(str(ctx.message.guild.id)) - await ctx.send(":thumbsup:") @commands.command() async def checkcog(self, ctx, *, n): diff --git a/cogs/internet.py b/cogs/internet.py index 7cfebe5..1adc3a7 100644 --- a/cogs/internet.py +++ b/cogs/internet.py @@ -10,16 +10,6 @@ import gmplot from util_functions import * from global_config import configboi -from server_config import serverconfig - -from better_profanity import profanity - -profanity.load_censor_words( - whitelist_words=open("data/whitelist_words.txt").read().split("\n") -) - -profanity.add_censor_words(open("data/blacklist_words.txt").read().split("\n")) - # Fun internet things class Internet(commands.Cog): """Useful tools on the interwebs""" @@ -27,7 +17,6 @@ class Internet(commands.Cog): def __init__(self, bot): self.bot = bot self.confmgr = configboi("config.txt", False) - self.sconf = serverconfig() async def getasjson(self, url): try: diff --git a/requirements.txt b/requirements.txt index a501f2e..ec26763 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ py-cord[voice] discord-pretty-help -requests \ No newline at end of file +requests +asyncio \ No newline at end of file diff --git a/util_functions.py b/util_functions.py index b0e1846..5437b42 100644 --- a/util_functions.py +++ b/util_functions.py @@ -19,9 +19,6 @@ syslog = BotLogger("system_log.txt") # .get is string VER = confmgr.get("VER") -PASTE_BASE = confmgr.get("PASTE_BASE") -PASTE_URL_BASE = confmgr.get("PASTE_URL_BASE") - HELP_LOC = confmgr.get("HELP_LOC") WRONG_PERMS = confmgr.get("WRONG_PERMS") @@ -29,18 +26,6 @@ WRONG_PERMS = confmgr.get("WRONG_PERMS") NEW_MEMBER = confmgr.get("NEW_MEMBER") INTRO_CHANNEL = confmgr.get("INTRO_CHANNEL") -# and a list (vv) -IMAGE_RESPONSES = confmgr.getaslist("IMAGE_RESPONSES") - -# and a boolean (vv) -DO_IMAGE_RESPONSE = confmgr.getasbool("DO_IMAGE_RESPONSES") -IMAGE_RESPONSE_PROB = confmgr.getasint("IMAGE_RESPONSE_PROB") - -# list of integers -MOD_IDS = confmgr.getasintlist("MOD_IDS") -# and an int (vv) -OWNER = confmgr.getasint("OWNER") - DEFAULT_STATUS_TYPE = confmgr.get("DEFAULT_STATUS_TYPE") DEFAULT_STATUS_TEXT = confmgr.get("DEFAULT_STATUS_TEXT") @@ -115,19 +100,6 @@ def imgbed(title, type, dat): e.set_image(url="attachment://" + dat) return e - -# Youtube Stuff -async def getytvid(link, songname): - syslog.log("Util-GetYTvid", "We're starting a download session") - syslog.log("Util-GetYTvid", "Target filename is: " + songname) - - await run_command_shell( - "cd bin && python3 download_one.py " + link + " " + songname + " && cd ../" - ) - - syslog.log("Util-GetYTvid", "All done!") - - # Simple file wrappers def check(fn): if os.path.exists(fn): @@ -146,7 +118,6 @@ def get(fn): with open(fn) as f: return f.read() - def ensure(fn): if not check(fn): os.makedirs(fn, exist_ok=True) @@ -162,75 +133,6 @@ def getstamp(): else: return "" - -def iswhitelisted(word): - if word in WHITELIST: - return True - else: - return False - - -# WTF IS THIS? -def purifylink(content): - sp1 = content.split("http")[1] - sp2 = sp1.split(" ")[0] - return "http" + sp2 - - def wrongperms(command): syslog.log("System", "Someone just failed to run: '" + command + "'") return WRONG_PERMS.replace("{command}", command) - - -# Maybe add: https://docs.python.org/3/library/shlex.html#shlex.quote ? -async def run_command_shell(command): - """Run command in subprocess (shell).""" - - # Create subprocess - process = await asyncio.create_subprocess_shell( - command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE - ) - - # Status - print("Started:", command, "(pid = " + str(process.pid) + ")", flush=True) - - # Wait for the subprocess to finish - stdout, stderr = await process.communicate() - - # Progress - if process.returncode == 0: - print("Done:", command, "(pid = " + str(process.pid) + ")", flush=True) - # Result - result = stdout.decode().strip() - else: - print("Failed:", command, "(pid = " + str(process.pid) + ")", flush=True) - # Result - result = stderr.decode().strip() - - # Return stdout - return result - - -def paste(text): - N = 25 - fn = ( - "".join( - random.choice( - string.ascii_uppercase + string.digits + string.ascii_lowercase - ) - for _ in range(N) - ) - + ".txt" - ) - with open(PASTE_BASE + fn, "w") as f: - f.write(text) - return PASTE_URL_BASE + fn - - -def getgeoip(ip): - url = "https://freegeoip.app/json/" + ip - headers = {"accept": "application/json", "content-type": "application/json"} - - response = requests.request("GET", url, headers=headers) - dat = response.json() - return dat