示例#1
0
async def on_ready():
    message = 'logged in as %s' % bot.user
    uid_message = 'user id %s' % bot.user.id
    separator = '-' * max(len(message), len(uid_message))
    print(separator)
    try:
        print(message)
    except: # some bot usernames with special chars fail on shitty platforms
        print(message.encode(errors='replace').decode())
    print(uid_message)
    if bot.track:
        print("anonymous tracking of bot usage is enabled")
    print("'unclosed client session' and 'unclosed connector' are not errors")
    print(separator)

    bot.session = aiohttp.ClientSession(loop=bot.loop, headers={"User-Agent": "AppuSelfBot"})

    bot.uptime = datetime.datetime.now()
    bot.icount = bot.message_count = bot.mention_count = bot.keyword_log = 0
    bot.self_log = bot.all_log = {}
    bot.imagedumps = []
    bot.is_stream = False
    bot.game = bot.game_interval = bot.avatar = bot.avatar_interval = bot.subpro = bot.keyword_found = None
    bot.game_time = bot.avatar_time = bot.gc_time = bot.refresh_time = time.time()
    bot.notify = load_notify_config()
    bot.command_count = {}
    bot.channel_last = [None, None]
    if not os.path.isfile('settings/ignored.json'):
        with open('settings/ignored.json', 'w', encoding="utf8") as fp:
            json.dump({'servers': []}, fp, indent=4)
    with open('settings/ignored.json', encoding="utf8") as fp:
        bot.ignored_servers = json.load(fp)

    if os.path.isfile('restart.txt'):
        with open('restart.txt', 'r', encoding="utf8") as re:
            channel = bot.get_channel(int(re.readline()))
            print('Bot has restarted.')
            await channel.send(bot.bot_prefix + 'Bot has restarted.')
        os.remove('restart.txt')
    bot.log_conf = load_log_config()
    bot.key_users = bot.log_conf['keyusers']

    if os.path.isfile('settings/games.json'):
        with open('settings/games.json', 'r+', encoding="utf8") as g:
            games = json.load(g)
            if type(games['games']) is list:
                bot.game = games['games'][0]
                bot.game_interval = games['interval']
            else:
                bot.game = games['games']
            if 'stream' not in games:
                games['stream'] = 'no'
            if games['stream'] == 'yes':
                bot.is_stream = True
            try:
                bot.status_type = games['status']
            except KeyError:
                bot.status_type = discord.ActivityType.playing
            g.seek(0)
            g.truncate()
            json.dump(games, g, indent=4)

    # Dealing with old versions updating
    if not os.path.isfile('settings/fc.json'):
        data = {"bnet_fc": "", "ds_fc": "", "psn_fc": "", "steam_fc": "", "switch_fc": "", "xbox_fc": ""}
        dataIO.save_json("settings/fc.json", data)
    if not os.path.isfile('settings/replacements.json'):
        data = {":lennyface:": "( ͡° ͜ʖ ͡°)", ":tableflip": "(╯°□°)╯︵ ┻━┻"}
        dataIO.save_json("settings/replacements.json", data)
    if not os.path.isfile('settings/moderation.json'):
        with open('settings/moderation.json', 'w', encoding="utf8") as m:
            mod = {}
            json.dump(mod, m, indent=4)
    if not os.path.isfile('settings/todo.json'):
        with open('settings/todo.json', 'w', encoding="utf8") as t:
            todo = {}
            json.dump(todo, t, indent=4)

    if not os.path.exists('avatars'):
        os.makedirs('avatars')
    if not os.path.isfile('settings/avatars.json'):
        with open('settings/avatars.json', 'w', encoding="utf8") as avis:
            json.dump({'password': '', 'interval': '0', 'type': 'random'}, avis, indent=4)
    with open('settings/avatars.json', 'r', encoding="utf8") as g:
        avatars = json.load(g)
    bot.avatar_interval = avatars['interval']
    if os.listdir('avatars') and avatars['interval'] != '0':
        all_avis = os.listdir('avatars')
        all_avis.sort()
        avi = random.choice(all_avis)
        bot.avatar = avi
    if not os.path.isfile('settings/optional_config.json'):
        conf = load_config()
        o_conf = {'google_api_key': conf['google_api_key'], 'custom_search_engine': conf['custom_search_engine'], 'mal_username': conf['mal_username'], 'mal_password': conf['mal_password']}
        with open('settings/optional_config.json', 'w', encoding="utf8") as oc:
            json.dump(o_conf, oc, indent=4)
    with open('settings/optional_config.json', 'r+', encoding="utf8") as fp:
        opt = json.load(fp)
        if 'embed_color' not in opt:
            opt['embed_color'] = ''
        if 'quoteembed_color' not in opt:
            opt['quoteembed_color'] = 'bc0b0b'
        if 'customcmd_color' not in opt:
            opt['customcmd_color'] = '27007A'
        if 'rich_embed' not in opt:
            opt['rich_embed'] = 'on'
        if 'default_status' not in opt:
            opt['default_status'] = 'idle'
        if 'ascii_font' not in opt:
            opt['ascii_font'] = 'big'
        if 'timezone' not in opt:
            opt['timezone'] = ''
        if '24hours' not in opt:
            opt['24hours'] = 'true'
        if 'password' not in opt:
            opt['password'] = ''
        if avatars['password'] != '' and opt['password'] == '':
            opt['password'] = avatars['password']
        bot.default_status = opt['default_status']
        fp.seek(0)
        fp.truncate()
        json.dump(opt, fp, indent=4)

    if not os.path.isfile('settings/github.json'):
        with open('settings/github.json', 'w', encoding="utf8") as fp:
            git = {}
            json.dump(git, fp, indent=4)
    with open('settings/github.json', 'r+', encoding="utf8") as fp:
        opt = json.load(fp)
        if 'username' not in opt:
            opt['username'] = ''
        if 'password' not in opt:
            opt['password'] = ''
        if 'reponame' not in opt:
            opt['reponame'] = ''
        fp.seek(0)
        fp.truncate()
        json.dump(opt, fp, indent=4)

    notif = load_notify_config()
    if notif['type'] == 'dm':
        if os.path.exists('notifier.txt'):
            pid = open('notifier.txt', 'r', encoding="utf8").read()
            try:
                p = psutil.Process(int(pid))
                p.kill()
            except:
                pass
            os.remove('notifier.txt')
        bot.subpro = subprocess.Popen([sys.executable, 'cogs/utils/notify.py'])
        with open('notifier.txt', 'w', encoding="utf8") as fp:
            fp.write(str(bot.subpro.pid))
async def on_ready():
    print('Logged in as')
    try:
        print(bot.user.name)
    except:
        pass
    print('User id:' + str(bot.user.id))
    print('------')
    bot.uptime = datetime.datetime.now()
    bot.icount = bot.message_count = bot.mention_count = bot.keyword_log = 0
    bot.self_log = bot.all_log = {}
    bot.imagedumps = []
    bot.is_stream = False
    bot.game = bot.game_interval = bot.avatar = bot.avatar_interval = bot.subpro = bot.keyword_found = None
    bot.game_time = bot.avatar_time = bot.gc_time = bot.refresh_time = time.time(
    )
    bot.notify = load_notify_config()
    if not os.path.isfile('settings/ignored.json'):
        with open('settings/ignored.json', 'w', encoding="utf8") as fp:
            json.dump({'servers': []}, fp, indent=4)
    with open('settings/ignored.json', encoding="utf8") as fp:
        bot.ignored_servers = json.load(fp)

    if os.path.isfile('restart.txt'):
        with open('restart.txt', 'r', encoding="utf8") as re:
            channel = bot.get_channel(int(re.readline()))
            print('Bot has restarted.')
            await channel.send(bot.bot_prefix + 'Bot has restarted.')
        os.remove('restart.txt')
    bot.log_conf = load_log_config()
    bot.key_users = bot.log_conf['keyusers']

    if os.path.isfile('settings/games.json'):
        with open('settings/games.json', 'r+', encoding="utf8") as g:
            games = json.load(g)
            if type(games['games']) is list:
                bot.game = games['games'][0]
                bot.game_interval = games['interval']
            else:
                bot.game = games['games']
            if 'stream' not in games:
                games['stream'] = 'no'
            if games['stream'] == 'yes':
                bot.is_stream = True
            g.seek(0)
            g.truncate()
            json.dump(games, g, indent=4)

    # Dealing with old versions updating
    if not os.path.isfile('settings/fc.json'):
        data = {
            "bnet_fc": "",
            "ds_fc": "",
            "psn_fc": "",
            "steam_fc": "",
            "switch_fc": "",
            "xbox_fc": ""
        }
        dataIO.save_json("settings/fc.json", data)
    if not os.path.isfile('settings/replacements.json'):
        data = {":lennyface:": "( ͡° ͜ʖ ͡°)", ":tableflip": "(╯°□°)╯︵ ┻━┻"}
        dataIO.save_json("settings/replacements.json", data)
    if not os.path.isfile('settings/moderation.json'):
        with open('settings/moderation.json', 'w', encoding="utf8") as m:
            mod = {}
            json.dump(mod, m, indent=4)
    if not os.path.isfile('settings/todo.json'):
        with open('settings/todo.json', 'w', encoding="utf8") as t:
            todo = {}
            json.dump(todo, t, indent=4)

    if not os.path.exists('avatars'):
        os.makedirs('avatars')
    if not os.path.isfile('settings/avatars.json'):
        with open('settings/avatars.json', 'w', encoding="utf8") as avis:
            json.dump({
                'password': '',
                'interval': '0',
                'type': 'random'
            },
                      avis,
                      indent=4)
    with open('settings/avatars.json', 'r', encoding="utf8") as g:
        avatars = json.load(g)
    bot.avatar_interval = avatars['interval']
    if os.listdir('avatars') and avatars['interval'] != '0':
        all_avis = os.listdir('avatars')
        all_avis.sort()
        avi = random.choice(all_avis)
        bot.avatar = avi
    if not os.path.isfile('settings/optional_config.json'):
        conf = load_config()
        o_conf = {
            'google_api_key': conf['google_api_key'],
            'custom_search_engine': conf['custom_search_engine'],
            'mal_username': conf['mal_username'],
            'mal_password': conf['mal_password']
        }
        with open('settings/optional_config.json', 'w', encoding="utf8") as oc:
            json.dump(o_conf, oc, indent=4)
    with open('settings/optional_config.json', 'r+', encoding="utf8") as fp:
        opt = json.load(fp)
        if 'embed_color' not in opt:
            opt['embed_color'] = ''
        if 'quoteembed_color' not in opt:
            opt['quoteembed_color'] = 'bc0b0b'
        if 'customcmd_color' not in opt:
            opt['customcmd_color'] = '27007A'
        if 'rich_embed' not in opt:
            opt['rich_embed'] = 'on'
        if 'default_status' not in opt:
            opt['default_status'] = 'idle'
        if 'ascii_font' not in opt:
            opt['ascii_font'] = 'big'
        if 'timezone' not in opt:
            opt['timezone'] = ''
        if 'password' not in opt:
            opt['password'] = ''
        if avatars['password'] != '' and opt['password'] == '':
            opt['password'] = avatars['password']
        bot.default_status = opt['default_status']
        fp.seek(0)
        fp.truncate()
        json.dump(opt, fp, indent=4)

    if not os.path.isfile('settings/github.json'):
        with open('settings/github.json', 'w', encoding="utf8") as fp:
            git = {}
            json.dump(git, fp, indent=4)
    with open('settings/github.json', 'r+', encoding="utf8") as fp:
        opt = json.load(fp)
        if 'username' not in opt:
            opt['username'] = ''
        if 'password' not in opt:
            opt['password'] = ''
        if 'reponame' not in opt:
            opt['reponame'] = ''
        fp.seek(0)
        fp.truncate()
        json.dump(opt, fp, indent=4)

    notif = load_notify_config()
    if notif['type'] == 'dm':
        if os.path.exists('notifier.txt'):
            pid = open('notifier.txt', 'r', encoding="utf8").read()
            try:
                p = psutil.Process(int(pid))
                p.kill()
            except:
                pass
            os.remove('notifier.txt')
        bot.subpro = subprocess.Popen([sys.executable, 'cogs/utils/notify.py'])
        with open('notifier.txt', 'w', encoding="utf8") as fp:
            fp.write(str(bot.subpro.pid))
示例#3
0
async def on_ready():
    print('Logged in as')
    try:
        print(bot.user.name)
    except:
        pass
    print('User id:' + str(bot.user.id))
    print('------')
    bot.uptime = datetime.datetime.now()
    bot.icount = bot.message_count = bot.mention_count = bot.keyword_log = 0
    bot.self_log = bot.all_log = {}
    bot.imagedumps = []
    bot.default_status = ''
    bot.is_stream = False
    bot.game = bot.game_interval = bot.avatar = bot.avatar_interval = bot.subpro = bot.keyword_found = None
    bot.game_time = bot.avatar_time = bot.gc_time = bot.refresh_time = time.time(
    )

    if os.path.isfile('restart.txt'):
        with open('restart.txt', 'r') as re:
            channel = bot.get_channel(re.readline())
            print('Bot has restarted.')
            await bot.send_message(channel, bot_prefix + 'Bot has restarted.')
        os.remove('restart.txt')
    with open('settings/log.json', 'r') as log:
        bot.log_conf = json.load(log)
        bot.key_users = bot.log_conf['keyusers']
    if os.path.isfile('settings/games.json'):
        with open('settings/games.json', 'r+') as g:
            games = json.load(g)
            if type(games['games']) is list:
                bot.game = games['games'][0]
                bot.game_interval = games['interval']
            else:
                bot.game = games['games']
            if 'stream' not in games:
                games['stream'] = 'no'
            if games['stream'] == 'yes':
                bot.is_stream = True
            g.seek(0)
            g.truncate()
            json.dump(games, g, indent=4)
    if not os.path.exists('avatars'):
        os.makedirs('avatars')
    if not os.path.isfile('settings/avatars.json'):
        with open('settings/avatars.json', 'w') as avis:
            json.dump({
                'password': '',
                'interval': '0',
                'type': 'random'
            },
                      avis,
                      indent=4)
    with open('settings/avatars.json', 'r') as g:
        avatars = json.load(g)
    bot.avatar_interval = avatars['interval']
    if os.listdir('avatars') and avatars['interval'] != '0':
        all_avis = os.listdir('avatars')
        all_avis.sort()
        avi = random.choice(all_avis)
        bot.avatar = avi
    if not os.path.isfile('settings/optional_config.json'):
        conf = load_config()
        o_conf = {
            'google_api_key': conf['google_api_key'],
            'custom_search_engine': conf['custom_search_engine'],
            'mal_username': conf['mal_username'],
            'mal_password': conf['mal_password']
        }
        with open('settings/optional_config.json', 'w') as oc:
            json.dump(o_conf, oc, indent=4)
    with open('settings/optional_config.json', 'r+') as fp:
        opt = json.load(fp)
        if 'customcmd_color' not in opt:
            opt['customcmd_color'] = '27007A'
        if 'rich_embed' not in opt:
            opt['rich_embed'] = 'on'
        if 'default_status' not in opt:
            opt['default_status'] = 'idle'
        if 'ascii_font' not in opt:
            opt['ascii_font'] = 'big'
        fp.seek(0)
        fp.truncate()
        json.dump(opt, fp, indent=4)
    with open('settings/notify.json', 'r') as n:
        notif = json.load(n)
    if notif['type'] == 'dm':
        if os.path.exists('notifier.txt'):
            pid = open('notifier.txt', 'r').read()
            try:
                p = psutil.Process(int(pid))
                p.kill()
            except:
                pass
            os.remove('notifier.txt')
        bot.subpro = subprocess.Popen([sys.executable, 'cogs/utils/notify.py'])
        with open('notifier.txt', 'w') as fp:
            fp.write(str(bot.subpro.pid))