Made the whole thing work
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
funcs/__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
|
39
Gwendolyn.py
39
Gwendolyn.py
@ -1,10 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import discord
|
||||
import asyncio
|
||||
import pickle
|
||||
import time
|
||||
import logging
|
||||
import codecs
|
||||
|
||||
from funcs import gwendolynFuncs
|
||||
import funcs
|
||||
|
||||
logging.basicConfig(filename="logfilename.log", level=logging.INFO)
|
||||
client = discord.Client()
|
||||
@ -27,36 +30,38 @@ async def on_message(message):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !help")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !help")
|
||||
file = open("help.txt","r")
|
||||
em = discord.Embed(title = "Help", description = file.read(),colour = 0x59f442)
|
||||
with codecs.open("help.txt",encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
print(text)
|
||||
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
|
||||
await message.channel.send(embed = em)
|
||||
|
||||
if message.content.lower().startswith("!hello"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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 ":
|
||||
await message.channel.send(gwendolynFuncs.roll_dice(message.author.name))
|
||||
await message.channel.send(funcs.roll_dice(message.author.name))
|
||||
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 "):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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 "):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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)
|
||||
await message.channel.send(embed = em1)
|
||||
if text2 != "":
|
||||
@ -106,14 +111,14 @@ async def on_message(message):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !movie")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !movie")
|
||||
async with message.channel.typing():
|
||||
title, plot, cover, cast = gwendolynFuncs.movieFunc()
|
||||
title, plot, cover, cast = funcs.movieFunc()
|
||||
if title == "error":
|
||||
await message.channel.send("An error occurred. Try again")
|
||||
else:
|
||||
@ -126,16 +131,16 @@ async def on_message(message):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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 "):
|
||||
gamePlaying = gwendolynFuncs.cap(message.content.lower().replace("!game ",""))
|
||||
gamePlaying = funcs.cap(message.content.lower().replace("!game ",""))
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
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+"'")
|
||||
@ -146,15 +151,15 @@ async def on_message(message):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\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",""))
|
||||
await message.channel.send(gwendolynFuncs.parseRoll(message.author.name,command))
|
||||
command = funcs.cap(message.content.lower().replace("!swroll",""))
|
||||
await message.channel.send(funcs.parseRoll(message.author.name,command))
|
||||
|
||||
elif message.content.lower().startswith("!swchar"):
|
||||
localtime = time.asctime(time.localtime(time.time()))
|
||||
print("\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",""))
|
||||
title, desc = gwendolynFuncs.parseChar(message.author.name,command)
|
||||
command = funcs.cap(message.content.lower().replace("!swchar",""))
|
||||
title, desc = funcs.parseChar(message.author.name,command)
|
||||
if title != "":
|
||||
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
|
||||
await message.channel.send(embed = em1)
|
||||
|
1
funcs/__init__.py
Normal file
1
funcs/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc, movieFunc, parseChar, parseRoll, spellFunc, monsterFunc, nameGen, tavernGen
|
@ -6,10 +6,10 @@ import random #used by imageFunc
|
||||
import urllib #used by imageFunc
|
||||
import imdb #used by movieFunc
|
||||
|
||||
from roll import dice
|
||||
from lookup import lookupFuncs
|
||||
from other import movie, generators
|
||||
from swfuncs import swchar, swroll
|
||||
from .roll import dice
|
||||
from .lookup import lookupFuncs
|
||||
from .other import movie, generators
|
||||
from .swfuncs import swchar, swroll
|
||||
|
||||
def roll_dice(author, rollStr: str = "1d20"):
|
||||
print("Rolling "+str(rollStr))
|
||||
@ -107,7 +107,7 @@ def movieFunc():
|
||||
ia = imdb.IMDb()
|
||||
|
||||
print("Picking a movie")
|
||||
movs = open("movies.txt", "r")
|
||||
movs = open("funcs/other/movies.txt", "r")
|
||||
movlist = movs.read().split("\n")
|
||||
mov = random.choice(movlist)
|
||||
movs.close()
|
||||
@ -140,10 +140,10 @@ def spellFunc(content):
|
||||
return lookupFuncs.spellFunc(content)
|
||||
|
||||
def monsterFunc(content):
|
||||
return lookupFuncs.spellFunc(content)
|
||||
return lookupFuncs.monsterFunc(content)
|
||||
|
||||
def nameGen():
|
||||
return generators.nameGen
|
||||
return generators.nameGen()
|
||||
|
||||
def tavernGen():
|
||||
return generators.tavernGen
|
||||
return generators.tavernGen()
|
||||
|
@ -23,8 +23,9 @@ def monsterFunc(content):
|
||||
print("")
|
||||
return("I don't know that monster...","","","","","")
|
||||
else:
|
||||
data = json.load(open('monsters.json', encoding = "utf8"))
|
||||
data = json.load(open('funcs/lookup/monsters.json', encoding = "utf8"))
|
||||
for monster in data:
|
||||
print("Found it!")
|
||||
if str(command) == monster["name"]:
|
||||
if monster["subtype"] != "":
|
||||
typs = (monster["type"]+" ("+monster["subtype"]+")")
|
||||
@ -112,7 +113,7 @@ def monsterFunc(content):
|
||||
def spellFunc(content):
|
||||
command = gf.cap(content.lower().replace("!spell ",""))
|
||||
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:
|
||||
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"]))
|
||||
|
@ -8,7 +8,7 @@ def make_pairs(corpus):
|
||||
yield (corpus[i], corpus[i+1])
|
||||
|
||||
def nameGen():
|
||||
names = open('names.txt', encoding='utf8').read()
|
||||
names = open('funcs/other/names.txt', encoding='utf8').read()
|
||||
corpus = list(names)
|
||||
|
||||
pairs = make_pairs(corpus)
|
||||
|
@ -8,7 +8,7 @@ from re import IGNORECASE
|
||||
|
||||
import numexpr
|
||||
|
||||
import errors
|
||||
from . import errors
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -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": {}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import json
|
||||
import string
|
||||
|
||||
def getName(user : str):
|
||||
with open("characters.json", "r") as f:
|
||||
with open("funcs/swfuncs/characters.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data:
|
||||
@ -81,7 +81,7 @@ def characterSheet(character : dict):
|
||||
return name, text1+"\n\n"+text2+divider+text3
|
||||
|
||||
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)
|
||||
|
||||
key = string.capwords(cmd.split(" ")[0])
|
||||
@ -107,7 +107,7 @@ def charData(user : str,cmd : str):
|
||||
|
||||
if type(lookUpResult) is dict:
|
||||
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)
|
||||
return "Changed " + data[user]["Name"] + "'s " + key
|
||||
else:
|
||||
@ -133,7 +133,7 @@ def charData(user : str,cmd : str):
|
||||
return "Can't add that"
|
||||
else:
|
||||
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)
|
||||
return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd
|
||||
else:
|
||||
@ -142,7 +142,7 @@ def charData(user : str,cmd : str):
|
||||
return "You don't have a character. You can make one with !swchar"
|
||||
|
||||
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)
|
||||
|
||||
if cmd == " ":
|
||||
@ -157,25 +157,25 @@ def parseChar(user : str, cmd : str):
|
||||
if user in data:
|
||||
return characterSheet(data[user])
|
||||
else:
|
||||
with open("templates.json", "r") as f:
|
||||
with open("funcs/swfuncs/templates.json", "r") as f:
|
||||
templates = json.load(f)
|
||||
newChar = templates["Character"]
|
||||
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)
|
||||
return "", "Character for " + user + " created"
|
||||
else:
|
||||
return "", charData(user,cmd)
|
||||
|
||||
def lightsaberChar(user : str):
|
||||
with open("characters.json", "r") as f:
|
||||
with open("funcs/swfuncs/characters.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data:
|
||||
return data[user]["Lightsaber Characteristic"]
|
||||
|
||||
def userHasChar(user : str):
|
||||
with open("characters.json", "r") as f:
|
||||
with open("funcs/swfuncs/characters.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
return user in data
|
||||
|
@ -3,9 +3,9 @@ import re
|
||||
import string
|
||||
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)
|
||||
|
||||
def roll(abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0):
|
||||
|
Reference in New Issue
Block a user