more trimming

pull/1/head
Matt C 3 years ago
parent c807b4ab71
commit 4989f51b24

@ -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

@ -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):

@ -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:

@ -1,3 +1,4 @@
py-cord[voice]
discord-pretty-help
requests
asyncio

@ -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

Loading…
Cancel
Save