more fixes from Gamerbot

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

4
.gitignore vendored

@ -1,3 +1,7 @@
# Custom
system_log.txt*
.cavetoken
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/

@ -1,6 +1,3 @@
# Token is BOTTOKEN in env-vars
# E.G. "BOTTOKEN=<something> python3 combo.py"
# Standard python imports
import os, string, unicodedata, sys, re, random, time, datetime, subprocess, json, traceback
import urllib.parse
@ -158,10 +155,10 @@ if UNLOAD_COGS is not None:
except:
syslog.log("Main", "Failed to remove '" + item + "'")
if os.environ["bottoken"] != "":
bot.run(os.environ["bottoken"])
if check(".cavetoken"):
token = open(".cavetoken").read().strip()
else:
print(
"You need to call this file with a variable 'bottoken' set to your bot token."
)
sys.exit(1)
fail("No token found in .cavetoken")
bot.run(token)

@ -5,7 +5,6 @@ import urllib
import discord
from discord.ext import commands
import asyncio
import gmplot
from util_functions import *
from global_config import configboi

@ -13,7 +13,7 @@ DEFAULT_STATUS_TYPE:playing
# These are currently the only substitutions
# - {number_users}
# - {guild_count}
DEFAULT_STATUS_TEXT:ooga booga w/ {number_users}
DEFAULT_STATUS_TEXT:ooga booga w/ {number_users} friends
# Any default cogs you don't want to load:
# Example: UNLOAD_COGS:Internet,Speak
@ -21,6 +21,9 @@ DEFAULT_STATUS_TEXT:ooga booga w/ {number_users}
# Blank is fine, too
UNLOAD_COGS:
# Who gets all log messages, and run extra-privileged commands
OWNER:117445905572954121
# Text for messages:
# Note {command} is the only substitution allowed here (we do auto-mention the user)
WRONG_PERMS:You're not a special snowflake, so you can't run `{command}`

@ -1,125 +0,0 @@
import os, sys, shutil
# Nonstandard to avoid depend loop
from logger import BotLogger
syslog = BotLogger("system_log.txt")
def check(fn):
if os.path.exists(fn):
return True
else:
return False
class simpledb:
def __init__(self):
self.dbroot = "server-data/"
if not check(self.dbroot):
os.makedirs(self.dbroot)
def get(self, server, key):
serverdb = self.dbroot + server
keyp = serverdb + "/" + key
if not check(serverdb):
return "NOT SET"
else:
if not check(keyp):
return "NOT SET"
else:
with open(keyp) as f:
return str(f.read())
def set(self, server, key, value):
serverdb = self.dbroot + server
keyp = serverdb + "/" + key
if not check(serverdb):
os.makedirs(serverdb)
with open(keyp, "w") as f:
f.write(str(value))
def exists(self, server):
serverdb = self.dbroot + server
if check(serverdb):
return True
else:
return False
def erase(self, server):
serverdb = self.dbroot + server
if self.exists(server):
shutil.rmtree(serverdb)
def listdata(self, server):
serverdb = self.dbroot + server
if self.exists(server):
data = ""
for f in os.listdir(serverdb):
if f != "blank":
data += f + " : " + open(serverdb + "/" + f).read() + "\n"
return data
else:
return "No DB for " + server
# ____________________________________________
class serverconfig:
def __init__(self):
self.db = simpledb()
def showdata(self, server):
server = str(server)
data = self.db.listdata(server)
out = "Data for `" + server + "`:\n```" + data + "```"
return out
def checkinit(self, server):
server = str(server)
if self.db.exists(server):
return True
else:
self.db.set(server, "blank", "blank")
return False
def getstring(self, server, key):
server = str(server)
return self.db.get(server, key)
def getint(self, server, key):
server = str(server)
val = self.db.get(server, key)
if val == "NOT SET":
return -1
else:
return int(self.db.get(server, key))
def getbool(self, server, key):
server = str(server)
val = self.db.get(server, key)
if val == "NOT SET":
return False
else:
if "true" in self.db.get(server, key):
return True
else:
return False
def set(self, server, key, value):
server = str(server)
key = str(key)
value = str(value)
self.db.set(server, key, value)
def rs(self, server):
server = str(server)
self.db.erase(server)
# GUILD ID:
# - mods
# - swears_censored
# - require_privileges
# - announcements

@ -30,6 +30,8 @@ DEFAULT_STATUS_TYPE = confmgr.get("DEFAULT_STATUS_TYPE")
DEFAULT_STATUS_TEXT = confmgr.get("DEFAULT_STATUS_TEXT")
UNLOAD_COGS = confmgr.getaslist("UNLOAD_COGS")
OWNER = confmgr.get("OWNER")
# <-------------- End --------------------->
# <--------------Colors Start-------------->
@ -53,9 +55,6 @@ white = 0xF9F9F6
cream = 0xFFDAB9
# <--------------Colors End-------------->
WHITELIST = []
def strip_dangerous(text):
remove = [";", "&&", "&", '"']
for thing in remove:
@ -136,3 +135,7 @@ def getstamp():
def wrongperms(command):
syslog.log("System", "Someone just failed to run: '" + command + "'")
return WRONG_PERMS.replace("{command}", command)
def fail(msg):
syslog.log("System ERROR", msg)
sys.exit(1)
Loading…
Cancel
Save