async def error(errorMessage, bot): channel = bot.get_channel(loadConfig('./jbot')['channel']['error']) writeToLog(errorMessage) logErrorToChat = loadConfig('./jbot')['loging']['LogErrorsToChat'] if logErrorToChat: return await channel.send(errorHolder(errorMessage))
async def sendDailyCuteImage(): channel = bot.get_channel( loadConfig('config')['sendtime']['sendChannelID']) if isTime( loadConfig('config')['sendtime']['hour'], loadConfig('config')['sendtime']['minute']): writeToLog( f"Sending cute image to {loadConfig('config')['sendtime']['sendChannelID']}" ) await channel.send(file=downloadUnsplashImage(randomCategory())) remove("img.jpg")
def downloadUnsplashImage(category) -> discord.File: source = PyUnsplashSourceClient( width=loadConfig('config')['unsplashSource']["image_width"], height=loadConfig('config')['unsplashSource']["image_height"]) writeToLog("Fetching image from Unsplash source") img = (source.random_image().search(category)).get() writeToLog("Saving image that got Fetched Unsplash source locally") img.save_as('img.jpg') return discord.File("img.jpg")
async def errorAndLogOut(errormessage, bot): logErrorToChat = loadConfig('./jbot')['loging']['LogErrorsToChat'] if logErrorToChat: await error(errormessage, bot) writeToLog(errormessage) await bot.logout()
def writeToLog(logText): logContents = f"{logText} \n" logText = f"{logDateTime()}{logContents}" writeLog = loadConfig('./jbot')['loging']['outputLog'] dailyLog = loadConfig('./jbot')['loging']['dailyLogs'] print(logText) if dailyLog: logFileName = logDate() else: logFileName = loadConfig('./jbot')['loging']['logFileName'] if writeLog: with open(logFileName, 'a') as logFile: logFile.write(logText)
async def sendCuteImage(self, ctx, animal) -> None: if animal in loadConfig('config')['unsplashSource']["tags"]: await ctx.send(file=downloadUnsplashImage(animal)) else: writeToLog( f"Cute command called by {ctx.author} with invalid argument off {animal}" ) await ctx.send(f""" **\"{animal}\"** is not a valid option. Please use on the the following: {buildCategoryText()} """)
import settings from jbot.config import loadConfig from jbot.time import isTime from jbot.init import initBot from jbot.log import writeToLog from cogs.cutnessDailyCog import CutenessDaily from unsplashImageDownload import (downloadUnsplashImage) from category import randomCategory from os import remove botConfig = loadConfig('jbot') bot = initBot() @bot.event async def on_ready(): writeToLog("loading cogs") bot.add_cog(CutenessDaily(bot)) writeToLog("Starting timers") sendDailyCuteImage.start() writeToLog("Bot is ready")
from discord.ext import commands from jbot.config import configFileExist, createJbotConfigFile, loadConfig from jbot.log import writeToLog jbotConfig = loadConfig('jbot') def initBot() -> commands.Bot: if configFileExist('jbot'): return commands.Bot(command_prefix = jbotConfig['bot']['prefix']) else: writeToLog("Could not find the Jbot config file. Creating one now") createJbotConfigFile()
async def errorCTX(errmessage, ctx): writeToLog(errorString) logErrorToChat = loadConfig('./jbot')['loging']['LogErrorsToChat'] if logErrorToChat: await ctx.send(errorHolder(errmessage))
from jbot.config import loadConfig from datetime import datetime errorString = loadConfig('./jbot')['messages']['error'] def errorHolder(errorMessage): return f"{errorString} {errorMessage}" async def error(errorMessage, bot): channel = bot.get_channel(loadConfig('./jbot')['channel']['error']) writeToLog(errorMessage) logErrorToChat = loadConfig('./jbot')['loging']['LogErrorsToChat'] if logErrorToChat: return await channel.send(errorHolder(errorMessage)) async def errorAndLogOut(errormessage, bot): logErrorToChat = loadConfig('./jbot')['loging']['LogErrorsToChat'] if logErrorToChat: await error(errormessage, bot) writeToLog(errormessage) await bot.logout() async def errorCTX(errmessage, ctx): writeToLog(errorString)
def sourceTags() -> list: return loadConfig('config')['unsplashSource']["tags"]