diff --git a/Gwendolyn.py b/Gwendolyn.py index 7506c08..dfb1669 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -2,7 +2,7 @@ import discord, os, finnhub from discord.ext import commands from pymongo import MongoClient -from funcs import logThis, makeFiles, Money, Funcs, SwChar, SwDestiny, SwRoll, Games +from funcs import logThis, makeFiles, Money, Funcs, SwChar, SwDestiny, SwRoll, Games, Generators commandPrefix = "!" @@ -43,6 +43,8 @@ class Gwendolyn(commands.Bot): self.swroll = SwRoll(self) self.swdestiny = SwDestiny(self) + self.generator = Generators() + Games(self) self.money = Money(self) diff --git a/cogs/MiscCog.py b/cogs/MiscCog.py index 1d6449d..e9d5120 100644 --- a/cogs/MiscCog.py +++ b/cogs/MiscCog.py @@ -1,7 +1,7 @@ import discord, codecs, string, wolframalpha, requests, os from discord.ext import commands -from funcs import logThis, helloFunc, roll_dice, imageFunc, nameGen, tavernGen, movieFunc, cap, findWikiPage +from funcs import logThis, helloFunc, roll_dice, imageFunc, movieFunc, cap, findWikiPage from PIL import Image, ImageDraw, ImageFont class MiscCog(commands.Cog): @@ -10,6 +10,7 @@ class MiscCog(commands.Cog): """Runs misc commands.""" self.client = client self.client.remove_command("help") + self.generator = client.generator @commands.command(name = "help") async def helpCommand(self, ctx, *, content = ""): @@ -88,12 +89,12 @@ class MiscCog(commands.Cog): # Generates a random name @commands.command() async def name(self, ctx): - await ctx.send(nameGen()) + await ctx.send(self.generator.nameGen()) # Generates a random tavern name @commands.command() async def tavern(self, ctx): - await ctx.send(tavernGen()) + await ctx.send(self.generator.tavernGen()) # Sets the game Gwendolyn's playing @commands.command() diff --git a/funcs/__init__.py b/funcs/__init__.py index 36bc1ea..d08c4c9 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -1,6 +1,6 @@ """A collection of all Gwendolyn functions.""" -__all__ = ["Games" ,"helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToCommand", "Money", "spellFunc", "monsterFunc", "nameGen", "tavernGen", "movieFunc", "roll_dice", "SwChar", "SwDestiny", "SwRoll", "replaceMultiple","Funcs"] +__all__ = ["Games" ,"helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToCommand", "Money", "spellFunc", "monsterFunc", "Generators", "movieFunc", "roll_dice", "SwChar", "SwDestiny", "SwRoll", "replaceMultiple","Funcs"] from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToCommand @@ -10,7 +10,7 @@ from .games import Money, Games from .lookup import spellFunc, monsterFunc -from .other import nameGen, tavernGen, movieFunc +from .other import Generators, movieFunc from .roll import roll_dice diff --git a/funcs/games/werewolf.py b/funcs/games/werewolf.py index abd4f2f..fd8d774 100644 --- a/funcs/games/werewolf.py +++ b/funcs/games/werewolf.py @@ -77,14 +77,14 @@ class Werewolf(): channel = "#"+str(ctx.channel.id) if round == 0: await asyncio.sleep(120) + game = self.bot.database["werewolf games"].find_one({"_id":channel}) - AINumber = 1 while len(game["users"].keys()) >= minimumPlayers and len(game["users"].keys()) < minimumPlayersWithAI: user = {"role": None} self.bot.database["werewolf games"].update_one({"_id":"#"+str(ctx.channel.id)}, - {"$set":{"users."+str(AINumber):user}}) + {"$set":{"users."+self.bot.generator.nameGen():user}}) game = self.bot.database["werewolf games"].find_one({"_id":channel}) - AINumber += 1 + self.bot.database["werewolf games"].update_one({"_id":channel},{"$inc":{"round":1}}) await self.werewolfLoop(ctx,round+1) else: diff --git a/funcs/other/__init__.py b/funcs/other/__init__.py index d1b0edb..75add9a 100644 --- a/funcs/other/__init__.py +++ b/funcs/other/__init__.py @@ -1,6 +1,6 @@ """Misc. functions for Gwendolyn.""" -__all__ = ["nameGen", "tavernGen", "movieFunc"] +__all__ = ["Generators", "movieFunc"] -from .generators import nameGen, tavernGen +from .generators import Generators from .movie import movieFunc \ No newline at end of file diff --git a/funcs/other/generators.py b/funcs/other/generators.py index d3f6cce..032704c 100644 --- a/funcs/other/generators.py +++ b/funcs/other/generators.py @@ -3,89 +3,90 @@ import random from funcs import logThis -# Returns a list of all letter pairs in the text -def make_pairs(corpus): - for i in range(len(corpus)-1): - yield (corpus[i], corpus[i+1]) +class Generators(): + # Returns a list of all letter pairs in the text + def make_pairs(self, corpus): + for i in range(len(corpus)-1): + yield (corpus[i], corpus[i+1]) -# Returns a list of all letter triplets in the text -def make_triplets(corpus): - for i in range(len(corpus)-2): - yield (corpus[i], corpus[i+1], corpus[i+2]) + # Returns a list of all letter triplets in the text + def make_triplets(self, corpus): + for i in range(len(corpus)-2): + yield (corpus[i], corpus[i+1], corpus[i+2]) -# Generates a random name -def nameGen(): - # Makes a list of all names from "names.txt" - names = open('resources/names.txt', encoding='utf8').read() - corpus = list(names) + # Generates a random name + def nameGen(self): + # Makes a list of all names from "names.txt" + names = open('resources/names.txt', encoding='utf8').read() + corpus = list(names) - # Makes a list of pairs - pairs = make_pairs(corpus) - triplets = make_triplets(corpus) + # Makes a list of pairs + pairs = self.make_pairs(corpus) + triplets = self.make_triplets(corpus) - letter_dict = {} + letter_dict = {} - # Makes a dictionary of all letters that come after all other letters - for letter_1, letter_2 in pairs: - if letter_1 in letter_dict.keys(): - letter_dict[letter_1].append(letter_2) - else: - letter_dict[letter_1] = [letter_2] + # Makes a dictionary of all letters that come after all other letters + for letter_1, letter_2 in pairs: + if letter_1 in letter_dict.keys(): + letter_dict[letter_1].append(letter_2) + else: + letter_dict[letter_1] = [letter_2] - for letter_1, letter_2, letter_3 in triplets: - if letter_1+letter_2 in letter_dict.keys(): - letter_dict[letter_1+letter_2].append(letter_3) - else: - letter_dict[letter_1+letter_2] = [letter_3] + for letter_1, letter_2, letter_3 in triplets: + if letter_1+letter_2 in letter_dict.keys(): + letter_dict[letter_1+letter_2].append(letter_3) + else: + letter_dict[letter_1+letter_2] = [letter_3] - # Choses a random first letter - first_letter = random.choice(corpus) - - # Makes sure the first letter is not something a name can't start with. - while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n": + # Choses a random first letter first_letter = random.choice(corpus) - # Starts the name - chain = [first_letter] + # Makes sure the first letter is not something a name can't start with. + while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n": + first_letter = random.choice(corpus) - # Picks second letter - second_letter = random.choice(letter_dict[chain[-1]]) + # Starts the name + chain = [first_letter] - while second_letter == "\n": + # Picks second letter second_letter = random.choice(letter_dict[chain[-1]]) - chain.append(second_letter) + while second_letter == "\n": + second_letter = random.choice(letter_dict[chain[-1]]) - done = False + chain.append(second_letter) - # Creates the name one letter at a time - while done == False: - if random.randint(1,10) > 1: - try: - new_letter = random.choice(letter_dict[chain[-2]+chain[-1]]) - except: + done = False + + # Creates the name one letter at a time + while done == False: + if random.randint(1,10) > 1: + try: + new_letter = random.choice(letter_dict[chain[-2]+chain[-1]]) + except: + new_letter = random.choice(letter_dict[chain[-1]]) + else: new_letter = random.choice(letter_dict[chain[-1]]) - else: - new_letter = random.choice(letter_dict[chain[-1]]) - chain.append(new_letter) - # Ends name if the name ends - if new_letter == "\n": - done = True - genName = "".join(chain) - logThis("Generated "+genName) - # Returns the name - return(genName) + chain.append(new_letter) + # Ends name if the name ends + if new_letter == "\n": + done = True + genName = "".join(chain) + logThis("Generated "+genName) + # Returns the name + return(genName) -# Generates a random tavern name -def tavernGen(): - # Lists first parts, second parts and third parts of tavern names - fp = ["The Silver","The Golden","The Staggering","The Laughing","The Prancing","The Gilded","The Running","The Howling","The Slaughtered","The Leering","The Drunken","The Leaping","The Roaring","The Frowning","The Lonely","The Wandering","The Mysterious","The Barking","The Black","The Gleaming","The Tap-Dancing","The Sad","The Sexy","The Artificial","The Groovy","The Merciful","The Confused","The Pouting","The Horny","The Okay","The Friendly","The Hungry","The Handicapped","The Fire-breathing","The One-Eyed","The Psychotic","The Mad","The Evil","The Idiotic","The Trusty","The Busty"] - sp = ["Eel","Dolphin","Dwarf","Pegasus","Pony","Rose","Stag","Wolf","Lamb","Demon","Goat","Spirit","Horde","Jester","Mountain","Eagle","Satyr","Dog","Spider","Star","Dad","Rat","Jeremy","Mouse","Unicorn","Pearl","Ant","Crab","Penguin","Octopus","Lawyer","Ghost","Toad","Handjob","Immigrant","SJW","Dragon","Bard","Sphinx","Soldier","Salmon","Owlbear","Kite","Frost Giant","Arsonist"] - tp = [" Tavern"," Inn","","","","","","","","",""] + # Generates a random tavern name + def tavernGen(self): + # Lists first parts, second parts and third parts of tavern names + fp = ["The Silver","The Golden","The Staggering","The Laughing","The Prancing","The Gilded","The Running","The Howling","The Slaughtered","The Leering","The Drunken","The Leaping","The Roaring","The Frowning","The Lonely","The Wandering","The Mysterious","The Barking","The Black","The Gleaming","The Tap-Dancing","The Sad","The Sexy","The Artificial","The Groovy","The Merciful","The Confused","The Pouting","The Horny","The Okay","The Friendly","The Hungry","The Handicapped","The Fire-breathing","The One-Eyed","The Psychotic","The Mad","The Evil","The Idiotic","The Trusty","The Busty"] + sp = ["Eel","Dolphin","Dwarf","Pegasus","Pony","Rose","Stag","Wolf","Lamb","Demon","Goat","Spirit","Horde","Jester","Mountain","Eagle","Satyr","Dog","Spider","Star","Dad","Rat","Jeremy","Mouse","Unicorn","Pearl","Ant","Crab","Penguin","Octopus","Lawyer","Ghost","Toad","Handjob","Immigrant","SJW","Dragon","Bard","Sphinx","Soldier","Salmon","Owlbear","Kite","Frost Giant","Arsonist"] + tp = [" Tavern"," Inn","","","","","","","","",""] - # Picks one of each - genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp) - logThis("Generated "+genTav) + # Picks one of each + genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp) + logThis("Generated "+genTav) - # Return the name - return(genTav) + # Return the name + return(genTav)