🧹 PEP updating

This commit is contained in:
Nikolaj
2021-06-14 21:00:10 +02:00
parent 8f6c8b06be
commit 8c253aca3d
43 changed files with 343 additions and 333 deletions

View File

@ -1,10 +1,10 @@
"""A collections of utilities used by Gwendolyn and her functions."""
__all__ = ["Options", "Credentials", "databaseFuncs", "EventHandler",
__all__ = ["Options", "Credentials", "DatabaseFuncs", "EventHandler",
"ErrorHandler", "getParams", "logThis", "cap", "makeFiles",
"replaceMultiple", "emojiToCommand"]
from .helperClasses import Options, Credentials, databaseFuncs
from .eventHandlers import EventHandler, ErrorHandler
from .utilFunctions import (getParams, logThis, cap, makeFiles,
replaceMultiple, emojiToCommand, longStrings)
from .helper_classes import Options, Credentials, DatabaseFuncs
from .event_handlers import EventHandler, ErrorHandler
from .util_functions import (getParams, logThis, cap, makeFiles,
replaceMultiple, emojiToCommand, long_strings)

View File

@ -15,7 +15,7 @@ from discord.ext import commands # Used to compare errors with command
# errors
from discord_slash.context import SlashContext
from utils.utilFunctions import emojiToCommand
from utils.util_functions import emojiToCommand
class EventHandler():
@ -35,7 +35,9 @@ class EventHandler():
async def on_ready(self):
"""Log and sets status when it logs in."""
await self.bot.databaseFuncs.syncCommands()
slashCommandList = await self.bot.slash.to_dict()
print(slashCommandList['guild'][740652054388932679][13])
await self.bot.database_funcs.syncCommands()
name = self.bot.user.name
userid = str(self.bot.user.id)
loggedInMessage = f"Logged in as {name}, {userid}"
@ -59,14 +61,14 @@ class EventHandler():
args = " ".join([str(i) for i in ctx.args])
fullCommand = f"/{ctx.command}{subcommand}{subcommandGroup}{args}"
logMessage = f"{ctx.author.display_name} ran {fullCommand}"
self.bot.log(logMessage, str(ctx.channel_id), level=25)
log_message = f"{ctx.author.display_name} ran {fullCommand}"
self.bot.log(log_message, str(ctx.channel_id), level=25)
async def on_reaction_add(self, reaction: discord.Reaction,
user: discord.User):
"""Take action if the reaction is on a command message."""
if not user.bot:
tests = self.bot.databaseFuncs
tests = self.bot.database_funcs
message = reaction.message
channel = message.channel
reactedMessage = f"{user.display_name} reacted to a message"
@ -80,10 +82,10 @@ class EventHandler():
reactionTestParams = [message, f"#{str(user.id)}"]
if tests.connectFourReactionTest(*reactionTestParams):
if tests.connect_fourReactionTest(*reactionTestParams):
column = emojiToCommand(reaction.emoji)
params = [message, f"#{user.id}", column-1]
await self.bot.games.connectFour.placePiece(*params)
await self.bot.games.connect_four.placePiece(*params)
if plexData[0]:
plexFuncs = self.bot.other.bedreNetflix
@ -150,14 +152,14 @@ class ErrorHandler():
self.bot.log("Deleted message before I could add all reactions")
elif isinstance(error, commands.errors.MissingRequiredArgument):
self.bot.log(f"{error}", str(ctx.channel_id))
await ctx.send(self.bot.longStrings["missing parameters"])
await ctx.send(self.bot.long_strings["missing parameters"])
else:
params = [type(error), error, error.__traceback__]
exception = traceback.format_exception(*params)
exceptionString = "".join(exception)
logMessages = [f"exception in /{ctx.name}", f"{exceptionString}"]
self.bot.log(logMessages, str(ctx.channel_id), 40)
log_messages = [f"exception in /{ctx.name}", f"{exceptionString}"]
self.bot.log(log_messages, str(ctx.channel_id), 40)
if isinstance(error, discord.errors.NotFound):
self.bot.log("Context is non-existant", level=40)
else:
@ -172,5 +174,5 @@ class ErrorHandler():
exception = traceback.format_exc()
exceptionString = "".join(exception)
logMessages = [f"exception in {method}", f"{exceptionString}"]
self.bot.log(logMessages, level=40)
log_messages = [f"exception in {method}", f"{exceptionString}"]
self.bot.log(log_messages, level=40)

View File

@ -84,7 +84,7 @@ class Credentials():
data = sanitize(f.read())
self.token = data["bot token"]
self.finnhubKey = data["finnhub api key"]
self.finnhub_key = data["finnhub api key"]
self.wordnikKey = data["wordnik api key"]
self.mongoDBUser = data["mongodb user"]
self.mongoDBPassword = data["mongodb password"]
@ -93,7 +93,7 @@ class Credentials():
self.sonarrKey = data["sonarr api key"]
class databaseFuncs():
class DatabaseFuncs():
"""
Manages database functions.
@ -103,7 +103,7 @@ class databaseFuncs():
getID(userName: str) -> str
deleteGame(gameType: str, channel: str)
wipeGames()
connectFourReactionTest(message: discord.Message,
connect_fourReactionTest(message: discord.Message,
user: discord.User) -> bool
hangmanReactionTest(message: discord.Message,
user: discord.User) -> bool
@ -195,7 +195,7 @@ class databaseFuncs():
g = git.cmd.Git("")
g.pull()
def connectFourReactionTest(self, message: discord.Message,
def connect_fourReactionTest(self, message: discord.Message,
user: discord.User):
"""
Test if the given message is the current connect four game.
@ -219,12 +219,15 @@ class databaseFuncs():
channelSearch = {"_id": str(channel.id)}
game = self.bot.database["connect 4 games"].find_one(channelSearch)
filePath = f"resources/games/oldImages/connectFour{channel.id}"
with open(filePath, "r") as f:
oldImage = int(f.read())
filePath = f"resources/games/old_images/connect_four{channel.id}"
if os.path.isfile(filePath):
with open(filePath, "r") as f:
oldImage = int(f.read())
else:
oldImage = 0
if message.id == oldImage:
self.bot.log("They reacted to the connectFour game")
self.bot.log("They reacted to the connect_four game")
turn = game["turn"]
if user == game["players"][turn]:
return True
@ -255,7 +258,7 @@ class databaseFuncs():
hangman.
"""
channel = message.channel
filePath = f"resources/games/oldImages/hangman{channel.id}"
filePath = f"resources/games/old_images/hangman{channel.id}"
if os.path.isfile(filePath):
with open(filePath, "r") as f:
oldMessages = f.read().splitlines()

View File

@ -3,7 +3,7 @@ Contains utility functions used by parts of the bot.
*Functions*
-----------
longstrings() -> dict
long_strings() -> dict
getParams() -> dict
logThis(messages: Union[str, list], channel: str = "",
level: int = 20)
@ -18,7 +18,7 @@ import logging # Used for logging
import os # Used by makeFiles() to check if files exist
import sys # Used to specify printing for logging
import imdb # Used to disable logging for the module
from .helperClasses import Options # Used by getParams()
from .helper_classes import Options # Used by getParams()
# All of this is logging configuration
@ -45,16 +45,16 @@ imdb._logging.setLevel("CRITICAL") # Basically disables imdbpy
# logging, since it's printed to the terminal.
def longStrings():
def long_strings():
"""
Get the data from resources/longStrings.json.
Get the data from resources/long_strings.json.
*Returns*
---------
data: dict
The long strings and their keys.
"""
with open("resources/longStrings.json", "r") as f:
with open("resources/long_strings.json", "r") as f:
data = json.load(f)
return data
@ -116,8 +116,8 @@ def logThis(messages, channel: str = "", level: int = 20):
if level >= 25:
printer.log(level, printMessage)
for logMessage in messages:
logger.log(level, logMessage)
for log_message in messages:
logger.log(level, log_message)
def cap(s: str):