Maintinance 🔧

This commit is contained in:
NikolajDanger
2020-12-03 15:58:13 +01:00
parent d03ae74937
commit 1fb2df546e
6 changed files with 82 additions and 78 deletions

View File

@ -2,7 +2,7 @@ import discord, os, finnhub
from discord.ext import commands from discord.ext import commands
from pymongo import MongoClient 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 = "!" commandPrefix = "!"
@ -43,6 +43,8 @@ class Gwendolyn(commands.Bot):
self.swroll = SwRoll(self) self.swroll = SwRoll(self)
self.swdestiny = SwDestiny(self) self.swdestiny = SwDestiny(self)
self.generator = Generators()
Games(self) Games(self)
self.money = Money(self) self.money = Money(self)

View File

@ -1,7 +1,7 @@
import discord, codecs, string, wolframalpha, requests, os import discord, codecs, string, wolframalpha, requests, os
from discord.ext import commands 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 from PIL import Image, ImageDraw, ImageFont
class MiscCog(commands.Cog): class MiscCog(commands.Cog):
@ -10,6 +10,7 @@ class MiscCog(commands.Cog):
"""Runs misc commands.""" """Runs misc commands."""
self.client = client self.client = client
self.client.remove_command("help") self.client.remove_command("help")
self.generator = client.generator
@commands.command(name = "help") @commands.command(name = "help")
async def helpCommand(self, ctx, *, content = ""): async def helpCommand(self, ctx, *, content = ""):
@ -88,12 +89,12 @@ class MiscCog(commands.Cog):
# Generates a random name # Generates a random name
@commands.command() @commands.command()
async def name(self, ctx): async def name(self, ctx):
await ctx.send(nameGen()) await ctx.send(self.generator.nameGen())
# Generates a random tavern name # Generates a random tavern name
@commands.command() @commands.command()
async def tavern(self, ctx): async def tavern(self, ctx):
await ctx.send(tavernGen()) await ctx.send(self.generator.tavernGen())
# Sets the game Gwendolyn's playing # Sets the game Gwendolyn's playing
@commands.command() @commands.command()

View File

@ -1,6 +1,6 @@
"""A collection of all Gwendolyn functions.""" """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 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 .lookup import spellFunc, monsterFunc
from .other import nameGen, tavernGen, movieFunc from .other import Generators, movieFunc
from .roll import roll_dice from .roll import roll_dice

View File

@ -77,14 +77,14 @@ class Werewolf():
channel = "#"+str(ctx.channel.id) channel = "#"+str(ctx.channel.id)
if round == 0: if round == 0:
await asyncio.sleep(120) await asyncio.sleep(120)
game = self.bot.database["werewolf games"].find_one({"_id":channel}) game = self.bot.database["werewolf games"].find_one({"_id":channel})
AINumber = 1
while len(game["users"].keys()) >= minimumPlayers and len(game["users"].keys()) < minimumPlayersWithAI: while len(game["users"].keys()) >= minimumPlayers and len(game["users"].keys()) < minimumPlayersWithAI:
user = {"role": None} user = {"role": None}
self.bot.database["werewolf games"].update_one({"_id":"#"+str(ctx.channel.id)}, 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}) game = self.bot.database["werewolf games"].find_one({"_id":channel})
AINumber += 1
self.bot.database["werewolf games"].update_one({"_id":channel},{"$inc":{"round":1}}) self.bot.database["werewolf games"].update_one({"_id":channel},{"$inc":{"round":1}})
await self.werewolfLoop(ctx,round+1) await self.werewolfLoop(ctx,round+1)
else: else:

View File

@ -1,6 +1,6 @@
"""Misc. functions for Gwendolyn.""" """Misc. functions for Gwendolyn."""
__all__ = ["nameGen", "tavernGen", "movieFunc"] __all__ = ["Generators", "movieFunc"]
from .generators import nameGen, tavernGen from .generators import Generators
from .movie import movieFunc from .movie import movieFunc

View File

@ -3,89 +3,90 @@ import random
from funcs import logThis from funcs import logThis
# Returns a list of all letter pairs in the text class Generators():
def make_pairs(corpus): # Returns a list of all letter pairs in the text
for i in range(len(corpus)-1): def make_pairs(self, corpus):
yield (corpus[i], corpus[i+1]) for i in range(len(corpus)-1):
yield (corpus[i], corpus[i+1])
# Returns a list of all letter triplets in the text # Returns a list of all letter triplets in the text
def make_triplets(corpus): def make_triplets(self, corpus):
for i in range(len(corpus)-2): for i in range(len(corpus)-2):
yield (corpus[i], corpus[i+1], corpus[i+2]) yield (corpus[i], corpus[i+1], corpus[i+2])
# Generates a random name # Generates a random name
def nameGen(): def nameGen(self):
# Makes a list of all names from "names.txt" # Makes a list of all names from "names.txt"
names = open('resources/names.txt', encoding='utf8').read() names = open('resources/names.txt', encoding='utf8').read()
corpus = list(names) corpus = list(names)
# Makes a list of pairs # Makes a list of pairs
pairs = make_pairs(corpus) pairs = self.make_pairs(corpus)
triplets = make_triplets(corpus) triplets = self.make_triplets(corpus)
letter_dict = {} letter_dict = {}
# Makes a dictionary of all letters that come after all other letters # Makes a dictionary of all letters that come after all other letters
for letter_1, letter_2 in pairs: for letter_1, letter_2 in pairs:
if letter_1 in letter_dict.keys(): if letter_1 in letter_dict.keys():
letter_dict[letter_1].append(letter_2) letter_dict[letter_1].append(letter_2)
else: else:
letter_dict[letter_1] = [letter_2] letter_dict[letter_1] = [letter_2]
for letter_1, letter_2, letter_3 in triplets: for letter_1, letter_2, letter_3 in triplets:
if letter_1+letter_2 in letter_dict.keys(): if letter_1+letter_2 in letter_dict.keys():
letter_dict[letter_1+letter_2].append(letter_3) letter_dict[letter_1+letter_2].append(letter_3)
else: else:
letter_dict[letter_1+letter_2] = [letter_3] letter_dict[letter_1+letter_2] = [letter_3]
# Choses a random first letter # 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":
first_letter = random.choice(corpus) first_letter = random.choice(corpus)
# Starts the name # Makes sure the first letter is not something a name can't start with.
chain = [first_letter] while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n":
first_letter = random.choice(corpus)
# Picks second letter # Starts the name
second_letter = random.choice(letter_dict[chain[-1]]) chain = [first_letter]
while second_letter == "\n": # Picks second letter
second_letter = random.choice(letter_dict[chain[-1]]) 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 done = False
while done == False:
if random.randint(1,10) > 1: # Creates the name one letter at a time
try: while done == False:
new_letter = random.choice(letter_dict[chain[-2]+chain[-1]]) if random.randint(1,10) > 1:
except: 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]]) new_letter = random.choice(letter_dict[chain[-1]])
else: chain.append(new_letter)
new_letter = random.choice(letter_dict[chain[-1]]) # Ends name if the name ends
chain.append(new_letter) if new_letter == "\n":
# Ends name if the name ends done = True
if new_letter == "\n": genName = "".join(chain)
done = True logThis("Generated "+genName)
genName = "".join(chain) # Returns the name
logThis("Generated "+genName) return(genName)
# Returns the name
return(genName)
# Generates a random tavern name # Generates a random tavern name
def tavernGen(): def tavernGen(self):
# Lists first parts, second parts and third parts of tavern names # 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"] 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"] 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","","","","","","","","",""] tp = [" Tavern"," Inn","","","","","","","","",""]
# Picks one of each # Picks one of each
genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp) genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp)
logThis("Generated "+genTav) logThis("Generated "+genTav)
# Return the name # Return the name
return(genTav) return(genTav)