コード例 #1
0
ファイル: markov.py プロジェクト: SirBlockles/yosho
def reset(bot, update):
    """reset markov states"""
    global STATES, TRANSITIONS
    # initiate STATES and TRANSITIONS with one member (absorbing state)
    STATES = [' ']
    TRANSITIONS = lil_matrix((1, 1), dtype=int)
    pickle.dump([STATES, TRANSITIONS], open(MARKOV_PATH, 'wb+'))
    db_push(MARKOV_PATH)
    update.message.reply_text(text='Reset markov states.')
コード例 #2
0
ファイル: chat_moderation.py プロジェクト: SirBlockles/yosho
def sfw(bot, update, bot_globals):
    """toggles per-chat SFW setting"""
    chat = update.message.chat
    name = chat.title if chat.username is None else '@' + chat.username

    if name in bot_globals['SFW'].keys():
        bot_globals['SFW'][name] ^= True
    else:
        bot_globals['SFW'][name] = True

    pickle.dump(bot_globals['SFW'], open(bot_globals['SFW_PATH'], 'wb+'))
    db_push(bot_globals['SFW_PATH'])

    update.message.reply_text(
        text='Chat {} is SFW only: {}'.format(name, bot_globals['SFW'][name]))
コード例 #3
0
ファイル: bot_moderation.py プロジェクト: SirBlockles/yosho
def set_global(bot, update, bot_globals):
    """sets or displays int/bool bot globals"""
    args = [a.strip() for a in clean(update.message.text).split('=')]
    names = (k for k, v in bot_globals.items() if isinstance(v, (int, bool)))
    listed = ('{} = {}'.format(k, v) for k, v in bot_globals.items()
              if isinstance(v, (int, bool)))

    if len(args) > 1:
        if args[0] in names:
            if str(args[1]).isnumeric():
                bot_globals['GLOBALS'][args[0]] = int(args[1])

                for k, g in bot_globals.items():
                    if isinstance(g, (int, bool)):
                        if k in bot_globals['GLOBALS'].keys():
                            bot_globals[k] = bot_globals['GLOBALS'][k]
                bot_globals['logger'].level = bot_globals['LOGGING_LEVEL']

                pickle.dump(bot_globals['GLOBALS'],
                            open(bot_globals['GLOBALS_PATH'], 'wb+'))
                db_push(bot_globals['GLOBALS_PATH'])

                update.message.reply_text(
                    text='Global {} updated.'.format(args[0]))
            else:
                update.message.reply_text(
                    text=
                    'Globals type error.\n\nValue must be int.\nUse 1 or 0 for booleans.'
                )
        else:
            update.message.reply_text(
                text='Globals key error.\n\nThat global does not exist.')
    elif args[0] == '':
        update.message.reply_text(text='Globals:\n\n' + '\n'.join(listed))
    else:
        update.message.reply_text(
            text=
            'Globals syntax error.\n\nProper usage is /global <global> = <value>'
        )
コード例 #4
0
ファイル: markov.py プロジェクト: SirBlockles/yosho
def flush(bot, job):
    pickle.dump([STATES, TRANSITIONS], open(MARKOV_PATH, 'wb+'))
    db_push(MARKOV_PATH)
コード例 #5
0
ファイル: macro_processor.py プロジェクト: SirBlockles/yosho
def flush(bot, job):
    global INTERPRETERS
    INTERPRETERS = {}
    MacroSet.dump(MACROS, open(MACROS_PATH, 'w+'))
    db_push(MACROS_PATH)