diff --git a/funcs/__init__.py b/funcs/__init__.py index 0ad39a5..aadbe21 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -1 +1,7 @@ -from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc, movieFunc, parseChar, parseRoll, spellFunc, monsterFunc, nameGen, tavernGen \ No newline at end of file +from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc + +from .swfuncs import parseChar, parseRoll + +from .lookup import spellFunc, monsterFunc + +from .other import nameGen, tavernGen, movieFunc \ No newline at end of file diff --git a/funcs/gwendolynFuncs.py b/funcs/gwendolynFuncs.py index d4744a1..eb3316f 100644 --- a/funcs/gwendolynFuncs.py +++ b/funcs/gwendolynFuncs.py @@ -11,7 +11,7 @@ from .lookup import lookupFuncs from .other import movie, generators from .swfuncs import swchar, swroll -def roll_dice(author, rollStr: str = "1d20"): +def roll_dice(author : str, rollStr : str = "1d20"): print("Rolling "+str(rollStr)) if rollStr == '0/0': # easter eggs return("What do you expect me to do, destroy the universe?") @@ -19,7 +19,7 @@ def roll_dice(author, rollStr: str = "1d20"): adv = 0 if re.search('(^|\s+)(adv|dis)(\s+|$)', rollStr) is not None: adv = 1 if re.search('(^|\s+)adv(\s+|$)', rollStr) is not None else -1 - rollStr = re.sub('(adv|dis)(\s+|$)', '', rollStr) + rollStr = re.sub('(adv|dis)(\s+|$)', '', rollSt res = dice.roll(rollStr, adv=adv) out = res.result outStr = author + ' :game_die:\n' + out @@ -100,50 +100,3 @@ def imageFunc(): print("Successfully returned an image") print("") return(image) - -def movieFunc(): - try: - print("Creating IMDb object") - ia = imdb.IMDb() - - print("Picking a movie") - movs = open("funcs/other/movies.txt", "r") - movlist = movs.read().split("\n") - mov = random.choice(movlist) - movs.close() - - print("Searching for "+mov) - s_result = ia.search_movie(mov) - - print("Getting the data") - movie = s_result[0] - ia.update(movie) - cast = movie['cast'] - pcast = "" - for x in range(3): - if cast[x]: - pcast += cast[x]['name']+", " - print("Successfully ran !movie") - print("") - return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2]) - except: - print("Something bad happened...") - return("error","","","") - -def parseChar(user : str, cmd : str = ""): - return swchar.parseChar(user,cmd) - -def parseRoll(user : str, cmd : str = ""): - return swroll.parseRoll(user,cmd) - -def spellFunc(content): - return lookupFuncs.spellFunc(content) - -def monsterFunc(content): - return lookupFuncs.monsterFunc(content) - -def nameGen(): - return generators.nameGen() - -def tavernGen(): - return generators.tavernGen() diff --git a/funcs/lookup/__init__.py b/funcs/lookup/__init__.py new file mode 100644 index 0000000..5c748ff --- /dev/null +++ b/funcs/lookup/__init__.py @@ -0,0 +1 @@ +from .lookupFuncs import spellFunc, monsterFunc \ No newline at end of file diff --git a/funcs/other/__init__.py b/funcs/other/__init__.py new file mode 100644 index 0000000..8f788c5 --- /dev/null +++ b/funcs/other/__init__.py @@ -0,0 +1,2 @@ +from .generators import nameGen, tavernGen +from .movie import movieFunc \ No newline at end of file diff --git a/funcs/other/generators.py b/funcs/other/generators.py index 5a72823..0a6b339 100644 --- a/funcs/other/generators.py +++ b/funcs/other/generators.py @@ -36,7 +36,7 @@ def nameGen(): if new_letter == "\n": done = True genName = "".join(chain) - print("Generated "+genName+"\n") + print("Generated "+genName) return(genName) def tavernGen(): diff --git a/funcs/other/movie.py b/funcs/other/movie.py index e80a7f9..96d42dc 100644 --- a/funcs/other/movie.py +++ b/funcs/other/movie.py @@ -2,27 +2,30 @@ import imdb import random def movieFunc(): - print("Running !movie") - print("Creating IMDb object") - ia = imdb.IMDb() + try: + print("Creating IMDb object") + ia = imdb.IMDb() - print("Picking a movie") - movs = open("movies.txt", "r") - movlist = movs.read().split("\n") - mov = random.choice(movlist) - movs.close() + print("Picking a movie") + movs = open("funcs/other/movies.txt", "r") + movlist = movs.read().split("\n") + mov = random.choice(movlist) + movs.close() - print("Searching") - s_result = ia.search_movie(mov) + print("Searching for "+mov) + s_result = ia.search_movie(mov) - print("Picking the movie") - movie = s_result[0] - ia.update(movie) - cast = movie['cast'] - pcast = "" - for x in range(3): - if cast[x]: - pcast += cast[x]['name']+", " - print("Successfully ran !movie") - print("") - return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2]) + print("Getting the data") + movie = s_result[0] + ia.update(movie) + cast = movie['cast'] + pcast = "" + for x in range(3): + if cast[x]: + pcast += cast[x]['name']+", " + print("Successfully ran !movie") + print("") + return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2]) + except: + print("Something bad happened...") + return("error","","","") diff --git a/funcs/swfuncs/__init__.py b/funcs/swfuncs/__init__.py new file mode 100644 index 0000000..e4a73de --- /dev/null +++ b/funcs/swfuncs/__init__.py @@ -0,0 +1,2 @@ +from .swchar import parseChar +from .swroll import parseRoll \ No newline at end of file diff --git a/funcs/swfuncs/characters.json b/funcs/swfuncs/characters.json index 3f17672..49edd62 100644 --- a/funcs/swfuncs/characters.json +++ b/funcs/swfuncs/characters.json @@ -69,5 +69,76 @@ "Weapons": {}, "Talents": {}, "Force Powers": {} + }, + "TestUser": { + "Name": "New Character", + "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": 0, + "Agility": 0, + "Intellect": 0, + "Cunning": 0, + "Willpower": 0, + "Presence": 0 + }, + "Skills": { + "Astrogation": 0, + "Athletics": 0, + "Brawl": 0, + "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": {} } } \ No newline at end of file diff --git a/funcs/swfuncs/swchar.py b/funcs/swfuncs/swchar.py index 85c3fa5..8fa6451 100644 --- a/funcs/swfuncs/swchar.py +++ b/funcs/swfuncs/swchar.py @@ -165,6 +165,11 @@ def parseChar(user : str, cmd : str): json.dump(data,f,indent = 4) return "", "Character for " + user + " created" else: + if cmd == "purge": + del data[user] + with open("funcs/swfuncs/characters.json", "w") as f: + json.dump(data,f,indent = 4) + return "", "Character for " + user + " deleted" return "", charData(user,cmd) def lightsaberChar(user : str): diff --git a/gwendolynTest.py b/gwendolynTest.py new file mode 100644 index 0000000..1ba9dcd --- /dev/null +++ b/gwendolynTest.py @@ -0,0 +1,30 @@ +import unittest + +import funcs + +class testSwChar(unittest.TestCase): + def testNewChar(self): + text1, result = funcs.parseChar("TestUser","") + self.assertEqual(result,"Character for TestUser created") + + def testChangeName(self): + text1, result = funcs.parseChar("TestUser","name TestChar") + self.assertEqual(result,"Changed TestChar's Name to TestChar") + + def testChangeChar(self): + text1, result = funcs.parseChar("TestUser","characteristics brawn 1") + self.assertEqual(result,"Changed New Character's Characteristics") + + def testDelChar(self): + text1, result = funcs.parseChar("TestUser","purge") + self.assertEqual(result,"Character for TestUser deleted") + + +class testGwendolynFuncs(unittest.TestCase): + def testCap(self): + self.assertEqual(funcs.cap("planet of the apes"),"Planet of the Apes") + self.assertEqual(funcs.cap("the greatest showman"),"The Greatest Showman") + self.assertEqual(funcs.cap("i'm the best person!"),"I'm the Best Person!") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file