コード例 #1
0
def setvotes_command(bot, message):
    report_botan(message, 'slave_setvotes_cmd')
    yield bot.send_message(pgettext('New required votes count request',
                                    'Set new amount of required votes'),
                           reply_to_message=message,
                           reply_markup=ForceReply(True))
    return True
コード例 #2
0
def plaintext_reject_handler(bot, message, chat_id, message_id):
    msg = message['text'].strip()
    if len(msg) < 10:
        report_botan(message, 'slave_reply_short_msg')
        yield bot.send_message(pgettext(
            'Reject message is too short',
            'Reject message is too short (10 symbols required), try '
            'again or send /cancel'),
                               reply_to_message=message,
                               reply_markup=ForceReply(True))
    else:
        yield bot.decline_message(
            {
                'chat': {
                    'id': chat_id
                },
                'message_id': message_id
            }, 0, False)
    try:
        yield bot.send_message(pgettext(
            'Message to user in case of rejection',
            "Your post has been rejected. "
            "Reason:\n> {reject_reason}").format(reject_reason=msg),
                               chat_id=chat_id,
                               reply_to_message_id=message_id)
        yield bot.send_message(pgettext('Rejection delivery confirmation',
                                        'Message sent and post rejected'),
                               reply_to_message=message)
    except Exception as e:
        yield bot.send_message(
            pgettext('Rejection failed',
                     'Message sending failed: {reason}').format(reason=str(e)),
            reply_to_message=message)

    return True
コード例 #3
0
ファイル: ban.py プロジェクト: mhverbakel/boterator
def ban_command(bot, callback_query, user_id):
    report_botan(callback_query, 'slave_ban_cmd')

    if int(user_id) == bot.owner_id:
        yield bot.answer_callback_query(
            callback_query['id'],
            pgettext('Somebody trying to ban the owner',
                     'It\'s not allowed to ban the bot owner'))
        return None

    if int(user_id) == callback_query['from']['id']:
        yield bot.answer_callback_query(
            callback_query['id'],
            pgettext('Somebody trying to ban himself',
                     'It\'s not allowed to ban yourself'))
        return None

    cur = yield bot.db.execute(
        'SELECT banned_at FROM users WHERE bot_id = %s AND user_id = %s',
        (bot.bot_id, user_id))
    row = cur.fetchone()
    if row and row[0]:
        yield bot.answer_callback_query(
            callback_query['id'],
            pgettext('User already banned', 'User already banned'))
        return None

    msg = pgettext('Ban reason request', 'Please enter a ban reason for the user, @{moderator_username}')\
        .format(moderator_username=callback_query['from']['username'])
    yield bot.send_message(msg,
                           chat_id=bot.moderator_chat_id,
                           reply_markup=ForceReply(True))
    yield bot.answer_callback_query(callback_query['id'])
    return {'user_id': user_id}
コード例 #4
0
def setdelay_command(bot, message):
    report_botan(message, 'slave_setdelay_cmd')
    yield bot.send_message(pgettext(
        'New delay request',
        'Set new delay value for messages posting (in minutes)'),
                           reply_to_message=message,
                           reply_markup=ForceReply(True))
    return True
コード例 #5
0
def settimeout_command(bot, message):
    report_botan(message, 'slave_settimeout_cmd')
    yield bot.send_message(pgettext(
        'New voting duration request',
        'Set new voting duration value (in hours, only a '
        'digits)'),
                           reply_to_message=message,
                           reply_markup=ForceReply(True))
    return True
コード例 #6
0
ファイル: reject.py プロジェクト: mhverbakel/boterator
def reject_command(bot, callback_query, chat_id, message_id):
    report_botan(callback_query, 'slave_reject_cmd')
    msg = pgettext('Reject message request', 'Please enter a reject reason, @{moderator_username}?') \
        .format(moderator_username=callback_query['from'].get('username', callback_query['from']['id']))
    yield bot.send_message(msg, chat_id=bot.moderator_chat_id, reply_markup=ForceReply(True))
    yield bot.answer_callback_query(callback_query['id'])
    return {
        'chat_id': chat_id,
        'message_id': message_id,
    }
コード例 #7
0
ファイル: ban.py プロジェクト: mhverbakel/boterator
def plaintext_ban_handler(bot, message, user_id):
    chat_id = message['chat']['id']

    cur = yield bot.db.execute(
        'SELECT banned_at FROM users WHERE bot_id = %s AND user_id = %s',
        (bot.bot_id, user_id))
    row = cur.fetchone()
    if row and row[0]:
        yield bot.send_message(pgettext(
            'Somebody banned a user faster than another one',
            'Somebody already banned the user. Be faster next time.'),
                               reply_to_message=message)
        return True

    msg = message['text'].strip()
    if len(msg) < 5:
        report_botan(message, 'slave_ban_short_msg')
        yield bot.send_message(pgettext(
            'Ban reason too short',
            'Reason is too short (5 symbols required), '
            'try again or send /cancel'),
                               reply_to_message=message,
                               reply_markup=ForceReply(True))
    else:
        report_botan(message, 'slave_ban_success')
        yield bot.send_chat_action(chat_id, bot.CHAT_ACTION_TYPING)
        try:
            yield bot.send_message(pgettext(
                'Message to user in case of ban',
                "You've been banned from further communication with this bot. "
                "Reason:\n> {ban_reason}").format(ban_reason=msg),
                                   chat_id=user_id)
        except:
            pass
        cur = yield bot.db.execute(
            'SELECT message FROM incoming_messages WHERE bot_id = %s AND owner_id = %s AND '
            'is_voting_success = FALSE AND is_voting_fail = FALSE AND is_published = FALSE',
            (
                bot.id,
                user_id,
            ))
        while True:
            row = cur.fetchone()
            if not row:
                break
            yield bot.decline_message(row[0], 0, False)

        yield bot.db.execute(
            'UPDATE users SET banned_at = NOW(), ban_reason = %s WHERE user_id = %s AND '
            'bot_id = %s', (msg, user_id, bot.id))
        yield bot.send_message(pgettext('Ban confirmation', 'User banned'),
                               reply_to_message=message)

        return True
コード例 #8
0
def setfreqlimit_command(bot, message):
    yield bot.send_message(pgettext(
        'New frequency limits request',
        'Please enter new value for messages frequency '
        'limits formatted like `{messages_count}/{days}`, '
        'or `0` to disable limits '
        '(e.g. `1/7` to set limit to 1 message per week)'),
                           reply_to_message=message,
                           parse_mode=bot.PARSE_MODE_MD,
                           reply_markup=ForceReply(True))
    return True
コード例 #9
0
def plaintext_startmessage_handler(bot, message):
    if message['text'] and len(message['text'].strip()) > 10:
        report_botan(message, 'slave_setstartmessage')
        yield bot.update_settings(message['from']['id'], start=message['text'].strip())
        yield bot.send_message(pgettext('Start message successfully changed', 'Start message updated'),
                               reply_to_message=message)
        return True
    else:
        report_botan(message, 'slave_setstartmessage_invalid')
        yield bot.send_message(pgettext('Too short start message entered', 'Invalid start message, you should write at '
                                                                           'least 10 symbols. Try again or type '
                                                                           '/cancel'),
                               reply_to_message=message, reply_markup=ForceReply(True))
コード例 #10
0
def plaintext_freqlimit_handler(bot, message):
    limits = message['text'].strip().split('/')

    if len(limits) == 1 and limits[0] == '0':
        yield bot.update_settings(message['from']['id'], msg_freq_limit=None)
        yield bot.send_message(pgettext('Limits reset', 'Limits reset'),
                               reply_to_message=message)
        return True
    elif len(limits) == 2 and limits[0].isdigit() and limits[1].isdigit():
        limits[0] = int(limits[0])
        limits[1] = int(limits[1])

        if limits[0] < 1:
            yield bot.send_message(pgettext(
                'Msg limit is too low',
                'Messages count limit must be greater than 0'),
                                   reply_to_message=message,
                                   reply_markup=ForceReply(True))
        elif limits[1] < 1:
            yield bot.send_message(pgettext(
                'Days limit is too low', 'Days count must be greater than 0'),
                                   reply_to_message=message,
                                   reply_markup=ForceReply(True))
        else:
            yield bot.update_settings(message['from']['id'],
                                      msg_freq_limit=[limits[0], limits[1]])
            yield bot.send_message(pgettext('Limits changed successfully',
                                            'Limits updated'),
                                   reply_to_message=message)
            return True
    else:
        yield bot.send_message(pgettext(
            'Non-well formatted freq limits provided',
            'Please use following format: `{messages_count}/{days}` (e.g. `1/7`), or '
            'send /cancel'),
                               reply_to_message=message,
                               parse_mode=bot.PARSE_MODE_MD,
                               reply_markup=ForceReply(True))
コード例 #11
0
def reply_command(bot, callback_query, chat_id, message_id):
    report_botan(callback_query, 'slave_reply_cmd')
    msg = pgettext('Reply message request', 'What message should I send to user, @{moderator_username}?') \
        .format(moderator_username=callback_query['from'].get('username', callback_query['from']['id']))
    fwd_id = yield bot.get_message_fwd_id(chat_id, message_id)
    yield bot.send_message(msg,
                           chat_id=bot.moderator_chat_id,
                           reply_markup=ForceReply(True),
                           reply_to_message_id=fwd_id)
    yield bot.answer_callback_query(callback_query['id'])
    return {
        'chat_id': chat_id,
        'message_id': message_id,
    }
コード例 #12
0
def plaintext_textlimits_handler(bot, message):
    limits = message['text'].strip().split('..')

    if len(limits) == 2 and limits[0].isdigit() and limits[1].isdigit():
        limits[0] = int(limits[0])
        limits[1] = int(limits[1])

        if limits[0] < 1:
            yield bot.send_message(pgettext('Bottom limit is too low', 'Bottom limit must be greater than 0'),
                                   reply_to_message=message, reply_markup=ForceReply(True))
        elif limits[1] <= limits[0]:
            yield bot.send_message(pgettext('Top limit is too low', 'Top limit must be greater than bottom one'),
                                   reply_to_message=message, reply_markup=ForceReply(True))
        else:
            yield bot.update_settings(message['from']['id'], text_min=limits[0], text_max=limits[1])
            yield bot.send_message(pgettext('Text limits changed successfully', 'Limits updated'),
                                   reply_to_message=message)
            return True
    else:
        yield bot.send_message(pgettext('Non-well formated text limits provided',
                                        'Please use following format: `{min_length}..{max_length}` (e.g. `1..10`), or '
                                        'send /cancel'), reply_to_message=message,
                               parse_mode=bot.PARSE_MODE_MD, reply_markup=ForceReply(True))
コード例 #13
0
def plaintext_delay_handler(bot, message):
    if message['text'].isdigit() and int(message['text']) >= 0:
        report_botan(message, 'slave_setdelay')
        yield bot.update_settings(message['from']['id'],
                                  delay=int(message['text']))
        yield bot.send_message(pgettext('Messages delay successfully changed',
                                        'Delay value updated'),
                               reply_to_message=message)
        return True
    else:
        report_botan(message, 'slave_setdelay_invalid')
        yield bot.send_message(pgettext(
            'Invalid delay value',
            'Invalid delay value. Try again or type /cancel'),
                               reply_to_message=message,
                               reply_markup=ForceReply(True))
コード例 #14
0
def plaintext_timeout_handler(bot, message):
    if message['text'].isdigit() and int(message['text']) > 0:
        report_botan(message, 'slave_settimeout')
        yield bot.update_settings(message['from']['id'],
                                  vote_timeout=int(message['text']))
        yield bot.send_message(pgettext('Voting duration successfully changed',
                                        'Voting duration updated'),
                               reply_to_message=message)
        return True
    else:
        report_botan(message, 'slave_settimeout_invalid')
        yield bot.send_message(pgettext(
            'Invalid voting duration value',
            'Invalid voting duration value. Try again or '
            'type /cancel'),
                               reply_to_message=message,
                               reply_markup=ForceReply(True))
コード例 #15
0
def plaintext_votes_handler(bot, message):
    if message['text'].isdigit() and int(message['text']) > 0:
        report_botan(message, 'slave_setvotes')
        yield bot.update_settings(message['from']['id'],
                                  votes=int(message['text']))
        yield bot.send_message(pgettext(
            'Required votes count successfully changed', 'Required votes '
            'amount updated'),
                               reply_to_message=message)
        return True
    else:
        report_botan(message, 'slave_setvotes_invalid')
        yield bot.send_message(pgettext(
            'Invalid votes amount value',
            'Invalid votes amount value. Try again or type '
            '/cancel'),
                               reply_to_message=message,
                               reply_markup=ForceReply(True))
コード例 #16
0
ファイル: reject.py プロジェクト: mhverbakel/boterator
def plaintext_reject_handler(bot, message, chat_id, message_id):
    msg = message['text'].strip()
    if len(msg) < 10:
        report_botan(message, 'slave_reply_short_msg')
        yield bot.send_message(pgettext('Reject message is too short', 'Reject message is too short (10 symbols required), try '
                                                                      'again or send /cancel'),
                               reply_to_message=message, reply_markup=ForceReply(True))
    else:
	    yield bot.db.execute('UPDATE incoming_messages SET is_voting_fail = TRUE WHERE id = %s AND '
							 'original_chat_id = %s',
							 (message_id, original_chat_id))
        try:
			yield bot.send_message(pgettext('Message to user in case of rejection',
                                            "Your post has been rejected. "
                                            "Reason:\n> {reject_reason}").format(reject_reason=msg),
                                   chat_id=user_id, reply_to_message_id=message_id)
            yield bot.send_message(pgettext('Rejection delivery confirmation', 'Message sent and post rejected'), reply_to_message=message)
        except Exception as e:
            yield bot.send_message(pgettext('Rejection failed', 'Message sending failed: {reason}').format(reason=str(e)),
                                   reply_to_message=message)
コード例 #17
0
def plaintext_reply_handler(bot, message, chat_id, message_id):
    msg = message['text'].strip()
    if len(msg) < 10:
        report_botan(message, 'slave_reply_short_msg')
        yield bot.send_message(pgettext(
            'Reply message is too short',
            'Message is too short (10 symbols required), try '
            'again or send /cancel'),
                               reply_to_message=message,
                               reply_markup=ForceReply(True))
    else:
        try:
            yield bot.send_message(msg,
                                   chat_id=chat_id,
                                   reply_to_message_id=message_id)
            yield bot.send_message(pgettext('Reply delivery confirmation',
                                            'Message sent'),
                                   reply_to_message=message)
        except Exception as e:
            yield bot.send_message(pgettext(
                'Reply failed', 'Failed: {reason}').format(reason=str(e)),
                                   reply_to_message=message)

        return True
コード例 #18
0
def setstartmessage_command(bot, message):
    report_botan(message, 'slave_setstartmessage_cmd')
    yield bot.send_message(pgettext('New start message request', 'Set new start message'), reply_to_message=message,
                           reply_markup=ForceReply(True))
    return True
コード例 #19
0
def settextlimits_command(bot, message):
    yield bot.send_message(pgettext('New length limits request', 'Please enter new value for length limits formatted '
                                                                 'like `{min_length}..{max_length}` (e.g. `1..10`)'),
                           reply_to_message=message, parse_mode=bot.PARSE_MODE_MD, reply_markup=ForceReply(True))
    return True