Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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")
Ejemplo n.º 3
0
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")
Ejemplo n.º 4
0
async def errorAndLogOut(errormessage, bot):
    logErrorToChat = loadConfig('./jbot')['loging']['LogErrorsToChat']
    if logErrorToChat:
        await error(errormessage, bot)

    writeToLog(errormessage)
    await bot.logout()
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
    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()}
""")
Ejemplo n.º 7
0
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")

Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
async def errorCTX(errmessage, ctx):
    writeToLog(errorString)
    logErrorToChat = loadConfig('./jbot')['loging']['LogErrorsToChat']

    if logErrorToChat:
        await ctx.send(errorHolder(errmessage))
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
def sourceTags() -> list:
    return loadConfig('config')['unsplashSource']["tags"]