mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Name restrictions removed, settings check (...)
Name restrictions have been removed. It no longer force upon the user the .Name() format. Settings are now checked every boot for consistency. Slot machine now shows credits left every play
This commit is contained in:
parent
bb96050eaf
commit
cf5e07851b
33
dataIO.py
33
dataIO.py
@ -1,6 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
default_settings = ('{"TRIVIA_ADMIN_ONLY": false, "EDIT_CC_ADMIN_ONLY": false, "PASSWORD": "PASSWORDHERE", "FILTER": true, "CUSTOMCOMMANDS": true, ' +
|
||||||
|
'"TRIVIAMAXSCORE": 10, "TRIVIADELAY": 15, "LOGGING": true, "EMAIL": "EMAILHERE", "ADMINROLE": "Transistor"}')
|
||||||
logger = logging.getLogger("__main__")
|
logger = logging.getLogger("__main__")
|
||||||
|
|
||||||
|
|
||||||
@ -39,4 +41,33 @@ def loadWords():
|
|||||||
with open("words.dat", "r") as f:
|
with open("words.dat", "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
w += line
|
w += line
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
def loadAndCheckSettings():
|
||||||
|
to_delete = []
|
||||||
|
try:
|
||||||
|
current_settings = fileIO("settings.json", "load")
|
||||||
|
default = json.loads(default_settings)
|
||||||
|
if current_settings.keys() != default.keys():
|
||||||
|
logger.warning("Something wrong detected with settings.json. Starting check...")
|
||||||
|
for field in default:
|
||||||
|
if field not in current_settings:
|
||||||
|
logger.info("Adding " + field + " field.")
|
||||||
|
current_settings[field] = default[field]
|
||||||
|
for field in current_settings:
|
||||||
|
if field not in default:
|
||||||
|
logger.info("Removing " + field + " field.")
|
||||||
|
to_delete.append(field)
|
||||||
|
for field in to_delete:
|
||||||
|
del current_settings[field]
|
||||||
|
logger.warning("Your settings.json was deprecated (missing or useless fields detected). I fixed it. " +
|
||||||
|
"If the file was missing any field I've added it and put default values. You might want to check it.")
|
||||||
|
fileIO("settings.json", "save", current_settings)
|
||||||
|
return current_settings
|
||||||
|
except IOError:
|
||||||
|
fileIO("settings.json", "save", json.loads(default_settings))
|
||||||
|
logger.error("Your settings.json is missing. I've created a new one. Edit it with your settings and restart me.")
|
||||||
|
exit(1)
|
||||||
|
except:
|
||||||
|
logger.error("Your settings.json seems to be invalid. Check it. If you're unable to fix it delete it and I'll create a new one the next start.")
|
||||||
|
exit(1)
|
||||||
@ -204,8 +204,10 @@ async def slotMachine(message, bid):
|
|||||||
else:
|
else:
|
||||||
await client.send_message(message.channel, "{}{} `Nothing! Lost bet.` ".format(display_reels, message.author.mention))
|
await client.send_message(message.channel, "{}{} `Nothing! Lost bet.` ".format(display_reels, message.author.mention))
|
||||||
withdrawMoney(message.author.id, bid)
|
withdrawMoney(message.author.id, bid)
|
||||||
|
await client.send_message(message.channel, "`Credits left: {}`".format(str(checkBalance(message.author.id))))
|
||||||
return True
|
return True
|
||||||
addMoney(message.author.id, bid)
|
addMoney(message.author.id, bid)
|
||||||
|
await client.send_message(message.channel, "`Current credits: {}`".format(str(checkBalance(message.author.id))))
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
|
|||||||
86
red.py
86
red.py
@ -26,8 +26,6 @@ import youtubeparser
|
|||||||
|
|
||||||
from sys import modules
|
from sys import modules
|
||||||
|
|
||||||
settings = dataIO.fileIO("settings.json", "load")
|
|
||||||
|
|
||||||
help = """**Commands list:**
|
help = """**Commands list:**
|
||||||
!flip - Flip a coin
|
!flip - Flip a coin
|
||||||
!rps [rock or paper o scissors] - Play rock paper scissors
|
!rps [rock or paper o scissors] - Play rock paper scissors
|
||||||
@ -112,12 +110,14 @@ async def on_message(message):
|
|||||||
await talk(message)
|
await talk(message)
|
||||||
|
|
||||||
if message.channel.id not in shush_list:
|
if message.channel.id not in shush_list:
|
||||||
if message.content.lower() == settings["NAME"].lower() + "?":
|
if message.content == client.user.name.upper() or message.content == client.user.name.upper() + "?":
|
||||||
await client.send_message(message.channel, "`" + choice(greetings) + "`")
|
|
||||||
elif message.content == settings["NAME"].upper():
|
|
||||||
await client.send_message(message.channel, "`" + choice(greetings_caps) + "`")
|
await client.send_message(message.channel, "`" + choice(greetings_caps) + "`")
|
||||||
|
elif message.content.lower() == client.user.name.lower() + "?":
|
||||||
|
await client.send_message(message.channel, "`" + choice(greetings) + "`")
|
||||||
|
elif message.content == client.user.mention + " ?" or message.content == client.user.mention + "?":
|
||||||
|
await client.send_message(message.channel, "`" + choice(greetings) + "`")
|
||||||
elif message.content == "!flip":
|
elif message.content == "!flip":
|
||||||
await client.send_message(message.channel, "`" + settings["NAME"] + " flips a coin and... " + choice(["HEADS!`", "TAILS!`"]))
|
await client.send_message(message.channel, "*flips a coin and... " + choice(["HEADS!*", "TAILS!*"]))
|
||||||
elif message.content.startswith("!rps"):
|
elif message.content.startswith("!rps"):
|
||||||
await rpsgame(message)
|
await rpsgame(message)
|
||||||
elif message.content == "!proverb":
|
elif message.content == "!proverb":
|
||||||
@ -247,11 +247,8 @@ async def on_message(message):
|
|||||||
|
|
||||||
@client.async_event
|
@client.async_event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
logger.info(settings["NAME"] + " is online. (" + client.user.id + ")")
|
logger.info("I'm online " + "(" + client.user.id + ")")
|
||||||
await gameSwitcher.changeGame(now=True)
|
await gameSwitcher.changeGame(now=True)
|
||||||
if client.user.name != settings["NAME"]:
|
|
||||||
name = "." + settings["NAME"] + "()"
|
|
||||||
await client.edit_profile(settings["PASSWORD"], username=name)
|
|
||||||
# cns = threading.Thread(target=console, args=[])
|
# cns = threading.Thread(target=console, args=[])
|
||||||
# cns.start() # console, WIP
|
# cns.start() # console, WIP
|
||||||
|
|
||||||
@ -951,9 +948,13 @@ async def sendPlaylist(message):
|
|||||||
|
|
||||||
async def shutdown(message):
|
async def shutdown(message):
|
||||||
if isMemberAdmin(message):
|
if isMemberAdmin(message):
|
||||||
await client.send_message(message.channel, "`" + settings["NAME"] + " shutting down... See you soon.` :hand:")
|
await client.send_message(message.channel, client.user.name + " shutting down... See you soon. :hand:")
|
||||||
await client.logout()
|
await client.logout()
|
||||||
exit(1)
|
try:
|
||||||
|
exit(1)
|
||||||
|
except SystemExit: #clean exit
|
||||||
|
logger.info("Shutting down as requested by " + message.author.id + "...")
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
await client.send_message(message.channel, "`I don't take orders from you.`")
|
await client.send_message(message.channel, "`I don't take orders from you.`")
|
||||||
|
|
||||||
@ -1041,13 +1042,9 @@ async def changeName(message):
|
|||||||
msg = message.content.split()
|
msg = message.content.split()
|
||||||
if len(msg) == 2:
|
if len(msg) == 2:
|
||||||
try:
|
try:
|
||||||
name = "." + msg[1] + "()"
|
await client.edit_profile(settings["PASSWORD"], username=msg[1])
|
||||||
await client.edit_profile(settings["PASSWORD"], username=name)
|
except Exception as e:
|
||||||
settings["NAME"] = msg[1]
|
print(e)
|
||||||
dataIO.fileIO("settings.json", "save", settings)
|
|
||||||
logger.info("Saved settings.")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
await client.send_message(message.channel, "`!name [new name]`")
|
await client.send_message(message.channel, "`!name [new name]`")
|
||||||
else:
|
else:
|
||||||
@ -1135,10 +1132,6 @@ def console():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
logger = loggerSetup()
|
|
||||||
|
|
||||||
dataIO.logger = logger
|
|
||||||
|
|
||||||
def loadDataFromFiles(loadsettings=False):
|
def loadDataFromFiles(loadsettings=False):
|
||||||
global proverbs, commands, trivia_questions, badwords, badwords_regex, shush_list
|
global proverbs, commands, trivia_questions, badwords, badwords_regex, shush_list
|
||||||
|
|
||||||
@ -1152,7 +1145,7 @@ def loadDataFromFiles(loadsettings=False):
|
|||||||
# logger.info("Loaded " + str(len(trivia_questions)) + " questions.")
|
# logger.info("Loaded " + str(len(trivia_questions)) + " questions.")
|
||||||
|
|
||||||
badwords = dataIO.fileIO("filter.json", "load")
|
badwords = dataIO.fileIO("filter.json", "load")
|
||||||
logger.info("Loaded " + str(len(badwords)) + " words.")
|
logger.info("Loaded " + str(len(badwords)) + " lists of filtered words.")
|
||||||
|
|
||||||
badwords_regex = dataIO.fileIO("regex_filter.json", "load")
|
badwords_regex = dataIO.fileIO("regex_filter.json", "load")
|
||||||
logger.info("Loaded " + str(len(badwords_regex)) + " regex lists.")
|
logger.info("Loaded " + str(len(badwords_regex)) + " regex lists.")
|
||||||
@ -1164,31 +1157,42 @@ def loadDataFromFiles(loadsettings=False):
|
|||||||
global settings
|
global settings
|
||||||
settings = dataIO.fileIO("settings.json", "load")
|
settings = dataIO.fileIO("settings.json", "load")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
global ball, greetings, greetings_caps, stopwatches, trivia_sessions, message, gameSwitcher, uptime_timer, musicPlayer, currentPlaylist
|
||||||
|
global logger, settings
|
||||||
|
|
||||||
loadDataFromFiles()
|
logger = loggerSetup()
|
||||||
|
dataIO.logger = logger
|
||||||
|
|
||||||
ball = ["As I see it, yes", "It is certain", "It is decidedly so", "Most likely", "Outlook good",
|
settings = dataIO.loadAndCheckSettings()
|
||||||
"Signs point to yes", "Without a doubt", "Yes", "Yes – definitely", "You may rely on it", "Reply hazy, try again",
|
|
||||||
"Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again",
|
|
||||||
"Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"]
|
|
||||||
|
|
||||||
greetings = ["Hey.", "Yes?", "Hi.", "I'm listening.", "Hello.", "I'm here."]
|
loadDataFromFiles()
|
||||||
greetings_caps = ["DON'T SCREAM", "WHAT", "WHAT IS IT?!", "ì_ì", "NO CAPS LOCK"]
|
|
||||||
|
|
||||||
stopwatches = {}
|
ball = ["As I see it, yes", "It is certain", "It is decidedly so", "Most likely", "Outlook good",
|
||||||
|
"Signs point to yes", "Without a doubt", "Yes", "Yes – definitely", "You may rely on it", "Reply hazy, try again",
|
||||||
|
"Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again",
|
||||||
|
"Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"]
|
||||||
|
|
||||||
trivia_sessions = []
|
greetings = ["Hey.", "Yes?", "Hi.", "I'm listening.", "Hello.", "I'm here."]
|
||||||
|
greetings_caps = ["DON'T SCREAM", "WHAT", "WHAT IS IT?!", "ì_ì", "NO CAPS LOCK"]
|
||||||
|
|
||||||
message = ""
|
stopwatches = {}
|
||||||
|
|
||||||
gameSwitcher = botPlays()
|
trivia_sessions = []
|
||||||
|
|
||||||
if "economy" in modules:
|
message = ""
|
||||||
economy.initialize(client)
|
|
||||||
|
|
||||||
uptime_timer = int(time.perf_counter())
|
gameSwitcher = botPlays()
|
||||||
|
|
||||||
musicPlayer = None
|
if "economy" in modules:
|
||||||
currentPlaylist = None
|
economy.initialize(client)
|
||||||
|
|
||||||
client.run(settings["EMAIL"], settings["PASSWORD"])
|
uptime_timer = int(time.perf_counter())
|
||||||
|
|
||||||
|
musicPlayer = None
|
||||||
|
currentPlaylist = None
|
||||||
|
|
||||||
|
client.run(settings["EMAIL"], settings["PASSWORD"])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user