Exemplo n.º 1
0
def main():
    config = load_config()
    logger.info("Warming up...")
    database.setup_database()

    bot.remove_command('help')

    for extension in extensions:
        try:
            bot.load_extension(extension)
            logger.info(f"{extension} loaded.")
        except Exception:
            exception = traceback.format_exc()
            logger.warning(exception)
    logger.info(f"{len(bot.cogs)} cogs across {len(bot.extensions)} extensions loaded.")

    shared.admin = config['admin']
    if 'general' in config:
        shared.general_channel = config['general']
    shared.name_restriction = utils.read_property('name_restriction', {})
    shared.enable_bg_game_rotation = utils.read_property('enable_bg_game_rotation', False)
    shared.banlist = utils.read_property('banlist', {})

    background.setup(bot, config)
    bot.run(config["OAuth_token"])
Exemplo n.º 2
0
 async def on_ready(self):
     if utils.read_property('restarting', False):
         utils.write_property('restarting', False)
         channel = self.bot.get_channel(
             utils.read_property('restarting_channel', None))
         previous_time = datetime.datetime.fromtimestamp(
             utils.read_property('restarting_time'))
         seconds = (datetime.datetime.now() - previous_time).total_seconds()
         await self.bot.send_message(
             channel,
             f'Restarted successfully in {round(seconds)} seconds.')
Exemplo n.º 3
0
    async def mal(self, ctx, member_raw: str = None):
        member = await utils.convert_member(ctx, member_raw, optional=True)
        mal_name = await utils.require_mal_username(ctx, member)
        if not mal_name:
            return

        true_name = utils.UserLookup.display_name_with_context(ctx, member)
        display_name = f'{true_name} - {mal_name}' if true_name and true_name.lower(
        ) != mal_name.lower() else mal_name

        message = discord.Embed(title=display_name)
        message.colour = 0x2E51A2

        embed_format = utils.read_property(
            'mal_embed_template', default=shared.mal_embed_link_template)
        message.set_image(url=embed_format.replace('<username>', mal_name))

        description = f'Profile: <https://myanimelist.net/profile/{mal_name}>\n'

        for entity in ['anime', 'manga']:
            description += f'{entity.title()}list (<https://myanimelist.net/{entity}list/{mal_name}>)\n'

            if shared.cache.get_entity_list(mal_name, entity):
                user = make_maluser(mal_name, entity)
                description += '\n'
                for status, items in user.foreach_status():
                    description += f'*{status}:* {len(items)}\n'
                description += '\n*Mean score* {0:.2f}\n'.format(
                    user.mean_score)
                description += f'*Days* {user.days}\n\n'

        message.description = description
        await ctx.bot.say(embed=message)
Exemplo n.º 4
0
def change_avatar_if_needed():
    wait_time = 3600 * 8
    now = datetime.datetime.now(datetime.timezone.utc).timestamp()
    time = utils.read_property('avatar_change_time', None)

    if not time or (now - time) >= wait_time:
        utils.write_property('avatar_change_time', now)
        run_avatar_script()
        return wait_time + 1
    return wait_time - (now - time) + 1
Exemplo n.º 5
0
def time_until_next_birthday():
    last_message = utils.read_property('last_birthday_check')
    if last_message:
        today = datetime.datetime.utcnow().strftime('%Y-%m-%d')
        if last_message != today:
            return 0
        else:
            now = datetime.datetime.utcnow()
            target = now.replace(hour=12, minute=0, second=0, microsecond=0) + datetime.timedelta(days=1)
            return (target - now).total_seconds()
    else:
        return 0
Exemplo n.º 6
0
#!/usr/bin/env python3

import asyncio
import discord
import re
from discord.ext import commands

import googletrans

from kanji_to_romaji import kanji_to_romaji
from utils import shared, utils, checks

moonrunes_auto_channel = utils.read_property('moonrunes_auto_channel')


class Languages:
    def __init__(self, bot):
        self.bot = bot

    async def on_message(self, message):
        if message.author != self.bot.user:
            if not message.content.strip().startswith(self.bot.command_prefix):
                await process_message(self.bot, message)

    @commands.command(pass_context=True,
                      aliases=['Tr', 'translate', 'Translate'])
    @checks.is_banned(permission=checks.PermissionLevel.Unsafe)
    async def tr(self, ctx, *, content):
        split_content = content.split(' ', 1)

        if '=>' in split_content[0]: