Made the whole thing work

This commit is contained in:
NikolajDanger
2020-03-24 00:07:17 +01:00
parent 7a5d462a68
commit 9bb95cfa40
12 changed files with 119 additions and 40 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
funcs/__pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class

View File

@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-
import discord import discord
import asyncio import asyncio
import pickle import pickle
import time import time
import logging import logging
import codecs
from funcs import gwendolynFuncs import funcs
logging.basicConfig(filename="logfilename.log", level=logging.INFO) logging.basicConfig(filename="logfilename.log", level=logging.INFO)
client = discord.Client() client = discord.Client()
@ -27,36 +30,38 @@ async def on_message(message):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !help") print("\n"+localtime+"\n"+message.author.name+" ran !help")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !help") logging.info("\n"+localtime+"\n"+message.author.name+" ran !help")
file = open("help.txt","r") with codecs.open("help.txt",encoding="utf-8") as f:
em = discord.Embed(title = "Help", description = file.read(),colour = 0x59f442) text = f.read()
print(text)
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
await message.channel.send(embed = em) await message.channel.send(embed = em)
if message.content.lower().startswith("!hello"): if message.content.lower().startswith("!hello"):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !hello") print("\n"+localtime+"\n"+message.author.name+" ran !hello")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !hello") logging.info("\n"+localtime+"\n"+message.author.name+" ran !hello")
await message.channel.send(gwendolynFuncs.helloFunc(message.author.name)) await message.channel.send(funcs.helloFunc(message.author.name))
elif message.content.lower().startswith("!roll"): elif message.content.lower().startswith("!roll"):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !roll") print("\n"+localtime+"\n"+message.author.name+" ran !roll")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !roll") logging.info("\n"+localtime+"\n"+message.author.name+" ran !roll")
if message.content.lower() == "!roll" or message.content.lower() == "!roll ": if message.content.lower() == "!roll" or message.content.lower() == "!roll ":
await message.channel.send(gwendolynFuncs.roll_dice(message.author.name)) await message.channel.send(funcs.roll_dice(message.author.name))
else: else:
await message.channel.send(gwendolynFuncs.roll_dice(message.author.name, message.content.lower().replace("!roll",""))) await message.channel.send(funcs.roll_dice(message.author.name, message.content.lower().replace("!roll","")))
elif message.content.lower().startswith("!spell "): elif message.content.lower().startswith("!spell "):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !spell") print("\n"+localtime+"\n"+message.author.name+" ran !spell")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !spell") logging.info("\n"+localtime+"\n"+message.author.name+" ran !spell")
await message.channel.send(gwendolynFuncs.spellFunc(message.content)) await message.channel.send(funcs.spellFunc(message.content))
elif message.content.lower().startswith("!monster "): elif message.content.lower().startswith("!monster "):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !monster") print("\n"+localtime+"\n"+message.author.name+" ran !monster")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !monster") logging.info("\n"+localtime+"\n"+message.author.name+" ran !monster")
title, text1, text2, text3, text4, text5 = gwendolynFuncs.monsterFunc(message.content) title, text1, text2, text3, text4, text5 = funcs.monsterFunc(message.content)
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF) em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
await message.channel.send(embed = em1) await message.channel.send(embed = em1)
if text2 != "": if text2 != "":
@ -106,14 +111,14 @@ async def on_message(message):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !image") print("\n"+localtime+"\n"+message.author.name+" ran !image")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !image") logging.info("\n"+localtime+"\n"+message.author.name+" ran !image")
await message.channel.send(gwendolynFuncs.imageFunc()) await message.channel.send(funcs.imageFunc())
elif message.content.lower().startswith("!movie"): elif message.content.lower().startswith("!movie"):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !movie") print("\n"+localtime+"\n"+message.author.name+" ran !movie")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !movie") logging.info("\n"+localtime+"\n"+message.author.name+" ran !movie")
async with message.channel.typing(): async with message.channel.typing():
title, plot, cover, cast = gwendolynFuncs.movieFunc() title, plot, cover, cast = funcs.movieFunc()
if title == "error": if title == "error":
await message.channel.send("An error occurred. Try again") await message.channel.send("An error occurred. Try again")
else: else:
@ -126,16 +131,16 @@ async def on_message(message):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !name") print("\n"+localtime+"\n"+message.author.name+" ran !name")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !name") logging.info("\n"+localtime+"\n"+message.author.name+" ran !name")
await message.channel.send(gwendolynFuncs.nameGen()) await message.channel.send(funcs.nameGen())
elif message.content.lower().startswith("!tavern"): elif message.content.lower().startswith("!tavern"):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !tavern") print("\n"+localtime+"\n"+message.author.name+" ran !tavern")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !tavern") logging.info("\n"+localtime+"\n"+message.author.name+" ran !tavern")
await message.channel.send(gwendolynFuncs.tavernGen()) await message.channel.send(funcs.tavernGen())
elif message.content.lower().startswith("!game "): elif message.content.lower().startswith("!game "):
gamePlaying = gwendolynFuncs.cap(message.content.lower().replace("!game ","")) gamePlaying = funcs.cap(message.content.lower().replace("!game ",""))
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'") print("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'") logging.info("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'")
@ -146,15 +151,15 @@ async def on_message(message):
localtime = time.asctime( time.localtime(time.time()) ) localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !swroll") print("\n"+localtime+"\n"+message.author.name+" ran !swroll")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !swroll") logging.info("\n"+localtime+"\n"+message.author.name+" ran !swroll")
command = gwendolynFuncs.cap(message.content.lower().replace("!swroll","")) command = funcs.cap(message.content.lower().replace("!swroll",""))
await message.channel.send(gwendolynFuncs.parseRoll(message.author.name,command)) await message.channel.send(funcs.parseRoll(message.author.name,command))
elif message.content.lower().startswith("!swchar"): elif message.content.lower().startswith("!swchar"):
localtime = time.asctime(time.localtime(time.time())) localtime = time.asctime(time.localtime(time.time()))
print("\n"+localtime+"\n"+message.author.name+" ran !swchar") print("\n"+localtime+"\n"+message.author.name+" ran !swchar")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !swchar") logging.info("\n"+localtime+"\n"+message.author.name+" ran !swchar")
command = gwendolynFuncs.cap(message.content.lower().replace("!swchar","")) command = funcs.cap(message.content.lower().replace("!swchar",""))
title, desc = gwendolynFuncs.parseChar(message.author.name,command) title, desc = funcs.parseChar(message.author.name,command)
if title != "": if title != "":
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF) em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
await message.channel.send(embed = em1) await message.channel.send(embed = em1)

1
funcs/__init__.py Normal file
View File

@ -0,0 +1 @@
from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc, movieFunc, parseChar, parseRoll, spellFunc, monsterFunc, nameGen, tavernGen

View File

@ -6,10 +6,10 @@ import random #used by imageFunc
import urllib #used by imageFunc import urllib #used by imageFunc
import imdb #used by movieFunc import imdb #used by movieFunc
from roll import dice from .roll import dice
from lookup import lookupFuncs from .lookup import lookupFuncs
from other import movie, generators from .other import movie, generators
from swfuncs import swchar, swroll from .swfuncs import swchar, swroll
def roll_dice(author, rollStr: str = "1d20"): def roll_dice(author, rollStr: str = "1d20"):
print("Rolling "+str(rollStr)) print("Rolling "+str(rollStr))
@ -107,7 +107,7 @@ def movieFunc():
ia = imdb.IMDb() ia = imdb.IMDb()
print("Picking a movie") print("Picking a movie")
movs = open("movies.txt", "r") movs = open("funcs/other/movies.txt", "r")
movlist = movs.read().split("\n") movlist = movs.read().split("\n")
mov = random.choice(movlist) mov = random.choice(movlist)
movs.close() movs.close()
@ -140,10 +140,10 @@ def spellFunc(content):
return lookupFuncs.spellFunc(content) return lookupFuncs.spellFunc(content)
def monsterFunc(content): def monsterFunc(content):
return lookupFuncs.spellFunc(content) return lookupFuncs.monsterFunc(content)
def nameGen(): def nameGen():
return generators.nameGen return generators.nameGen()
def tavernGen(): def tavernGen():
return generators.tavernGen return generators.tavernGen()

View File

@ -23,8 +23,9 @@ def monsterFunc(content):
print("") print("")
return("I don't know that monster...","","","","","") return("I don't know that monster...","","","","","")
else: else:
data = json.load(open('monsters.json', encoding = "utf8")) data = json.load(open('funcs/lookup/monsters.json', encoding = "utf8"))
for monster in data: for monster in data:
print("Found it!")
if str(command) == monster["name"]: if str(command) == monster["name"]:
if monster["subtype"] != "": if monster["subtype"] != "":
typs = (monster["type"]+" ("+monster["subtype"]+")") typs = (monster["type"]+" ("+monster["subtype"]+")")
@ -112,7 +113,7 @@ def monsterFunc(content):
def spellFunc(content): def spellFunc(content):
command = gf.cap(content.lower().replace("!spell ","")) command = gf.cap(content.lower().replace("!spell ",""))
print("Looking up "+command) print("Looking up "+command)
data = json.load(open('spells.json', encoding = "utf8")) data = json.load(open('funcs/lookup/spells.json', encoding = "utf8"))
if str(command) in data: if str(command) in data:
print("Returning spell information") print("Returning spell information")
spell_output = ("***"+str(command)+"***\n*"+str(data[str(command)]["level"])+" level "+str(data[str(command)]["school"])+"\nCasting Time: "+str(data[str(command)]["casting_time"])+"\nRange: "+str(data[str(command)]["range"])+"\nComponents: "+str(data[str(command)]["components"])+"\nDuration: "+str(data[str(command)]["duration"])+"*\n \n"+str(data[str(command)]["description"])) spell_output = ("***"+str(command)+"***\n*"+str(data[str(command)]["level"])+" level "+str(data[str(command)]["school"])+"\nCasting Time: "+str(data[str(command)]["casting_time"])+"\nRange: "+str(data[str(command)]["range"])+"\nComponents: "+str(data[str(command)]["components"])+"\nDuration: "+str(data[str(command)]["duration"])+"*\n \n"+str(data[str(command)]["description"]))

View File

@ -8,7 +8,7 @@ def make_pairs(corpus):
yield (corpus[i], corpus[i+1]) yield (corpus[i], corpus[i+1])
def nameGen(): def nameGen():
names = open('names.txt', encoding='utf8').read() names = open('funcs/other/names.txt', encoding='utf8').read()
corpus = list(names) corpus = list(names)
pairs = make_pairs(corpus) pairs = make_pairs(corpus)

View File

@ -8,7 +8,7 @@ from re import IGNORECASE
import numexpr import numexpr
import errors from . import errors
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -1,2 +1,73 @@
{ {
"Nikolaj": {
"Name": "Jared",
"Species": "",
"Career": "",
"Specialization Trees": [],
"Soak": 0,
"Wound Threshold": 0,
"Wounds": 0,
"Strain Threshold": 0,
"Strain": 0,
"Defense, Ranged": 0,
"Defense, Melee": 0,
"Force Rating": 0,
"Characteristics": {
"Brawn": 5,
"Agility": 0,
"Intellect": 0,
"Cunning": 0,
"Willpower": 0,
"Presence": 0
},
"Skills": {
"Astrogation": 0,
"Athletics": 0,
"Brawl": 1,
"Charm": 0,
"Coercion": 0,
"Computers": 0,
"Cool": 0,
"Coordination": 0,
"Core Worlds": 0,
"Discipline": 0,
"Gunnery": 0,
"Leadership": 0,
"Lightsaber": 0,
"Lore": 0,
"Mechanics": 0,
"Medicine": 0,
"Melee": 0,
"Negotiation": 0,
"Outer Rim": 0,
"Perception": 0,
"Piloting - Planetary": 0,
"Piloting - Space": 0,
"Ranged - Heavy": 0,
"Ranged - Light": 0,
"Resilience": 0,
"Skullduggery": 0,
"Stealth": 0,
"Streetwise": 0,
"Survival": 0,
"Underworld": 0,
"Vigilance": 0,
"Xenology": 0
},
"Lightsaber Characteristic": "Brawn",
"Obligations": {},
"Morality": {
"Emotional Weakness": "",
"Emotional Strength": "",
"Conflict": "",
"Morality": ""
},
"Credits": 0,
"Equipment": [],
"Armor": "",
"Critical Injuries": {},
"Weapons": {},
"Talents": {},
"Force Powers": {}
}
} }

View File

@ -2,7 +2,7 @@ import json
import string import string
def getName(user : str): def getName(user : str):
with open("characters.json", "r") as f: with open("funcs/swfuncs/characters.json", "r") as f:
data = json.load(f) data = json.load(f)
if user in data: if user in data:
@ -81,7 +81,7 @@ def characterSheet(character : dict):
return name, text1+"\n\n"+text2+divider+text3 return name, text1+"\n\n"+text2+divider+text3
def charData(user : str,cmd : str): def charData(user : str,cmd : str):
with open("characters.json", "r") as f: with open("funcs/swfuncs/characters.json", "r") as f:
data = json.load(f) data = json.load(f)
key = string.capwords(cmd.split(" ")[0]) key = string.capwords(cmd.split(" ")[0])
@ -107,7 +107,7 @@ def charData(user : str,cmd : str):
if type(lookUpResult) is dict: if type(lookUpResult) is dict:
data[user][key] = lookUpResult data[user][key] = lookUpResult
with open("characters.json", "w") as f: with open("funcs/swfuncs/characters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Changed " + data[user]["Name"] + "'s " + key return "Changed " + data[user]["Name"] + "'s " + key
else: else:
@ -133,7 +133,7 @@ def charData(user : str,cmd : str):
return "Can't add that" return "Can't add that"
else: else:
data[user][key] = cmd data[user][key] = cmd
with open("characters.json", "w") as f: with open("funcs/swfuncs/characters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd
else: else:
@ -142,7 +142,7 @@ def charData(user : str,cmd : str):
return "You don't have a character. You can make one with !swchar" return "You don't have a character. You can make one with !swchar"
def parseChar(user : str, cmd : str): def parseChar(user : str, cmd : str):
with open("characters.json", "r") as f: with open("funcs/swfuncs/characters.json", "r") as f:
data = json.load(f) data = json.load(f)
if cmd == " ": if cmd == " ":
@ -157,25 +157,25 @@ def parseChar(user : str, cmd : str):
if user in data: if user in data:
return characterSheet(data[user]) return characterSheet(data[user])
else: else:
with open("templates.json", "r") as f: with open("funcs/swfuncs/templates.json", "r") as f:
templates = json.load(f) templates = json.load(f)
newChar = templates["Character"] newChar = templates["Character"]
data[user] = newChar data[user] = newChar
with open("characters.json", "w") as f: with open("funcs/swfuncs/characters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "", "Character for " + user + " created" return "", "Character for " + user + " created"
else: else:
return "", charData(user,cmd) return "", charData(user,cmd)
def lightsaberChar(user : str): def lightsaberChar(user : str):
with open("characters.json", "r") as f: with open("funcs/swfuncs/characters.json", "r") as f:
data = json.load(f) data = json.load(f)
if user in data: if user in data:
return data[user]["Lightsaber Characteristic"] return data[user]["Lightsaber Characteristic"]
def userHasChar(user : str): def userHasChar(user : str):
with open("characters.json", "r") as f: with open("funcs/swfuncs/characters.json", "r") as f:
data = json.load(f) data = json.load(f)
return user in data return user in data

View File

@ -3,9 +3,9 @@ import re
import string import string
import json import json
import swchar from . import swchar
with open("skills.json", "r") as f: with open("funcs/swfuncs/skills.json", "r") as f:
skillData = json.load(f) skillData = json.load(f)
def roll(abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0): def roll(abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0):