Beispiel #1
0
def main():
    config = configparser.ConfigParser()
    config.read('bot.ini')

    updater = Updater(token=config['KEYS']['bot_api'], use_context=True)
    dispatcher = updater.dispatcher

    global SELF_CHAT_ID
    SELF_CHAT_ID = f'@{updater.bot.get_me().username}'

    rate_limit_tracker_handler = MessageHandler(~Filters.command, rate_limit_tracker)

    start_handler = CommandHandler('start', start)
    rules_handler = CommandHandler('rules', rules)
    rules_handler_hashtag = MessageHandler(Filters.regex(r'.*#rules.*'), rules)
    docs_handler = CommandHandler('docs', docs)
    wiki_handler = CommandHandler('wiki', wiki)
    sandwich_handler = MessageHandler(Filters.regex(r'(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?'),
                                      sandwich)
    off_on_topic_handler = MessageHandler(Filters.regex(r'(?i)[\s\S]*?\b(?<!["\\])(off|on)[- _]?topic\b'),
                                          off_on_topic)

    # We need several matches so Filters.regex is basically useless
    # therefore we catch everything and do regex ourselves
    # This should probably be in another dispatcher group
    # but I kept getting SystemErrors...
    github_handler = MessageHandler(Filters.text, github)
    forward_faq_handler = MessageHandler(Filters.regex(r'(?i).*#faq.*'), forward_faq)

    dispatcher.add_handler(rate_limit_tracker_handler, group=-1)

    # Note: Order matters!
    taghints.register(dispatcher)
    dispatcher.add_handler(forward_faq_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(rules_handler)
    dispatcher.add_handler(rules_handler_hashtag)
    dispatcher.add_handler(docs_handler)
    dispatcher.add_handler(wiki_handler)
    dispatcher.add_handler(sandwich_handler)
    dispatcher.add_handler(off_on_topic_handler)
    dispatcher.add_handler(github_handler)

    inlinequeries.register(dispatcher)
    dispatcher.add_error_handler(error)

    updater.start_polling()
    logger.info('Listening...')

    try:
        github_issues.set_auth(config['KEYS']['github_client_id'], config['KEYS']['github_client_secret'])
    except KeyError:
        logging.info('No github auth set. Rate-limit is 60 requests/hour without auth.')

    github_issues.init_issues(dispatcher.job_queue)

    updater.idle()
Beispiel #2
0
def main():
    config = configparser.ConfigParser()
    config.read('bot.ini')

    updater = Updater(token=config['KEYS']['bot_api'], use_context=True)
    dispatcher = updater.dispatcher

    global SELF_CHAT_ID
    SELF_CHAT_ID = f'@{updater.bot.get_me().username}'

    rate_limit_tracker_handler = MessageHandler(~Filters.command, rate_limit_tracker)

    start_handler = CommandHandler('start', start)
    rules_handler = CommandHandler('rules', rules)
    rules_handler_hashtag = MessageHandler(Filters.regex(r'.*#rules.*'), rules)
    docs_handler = CommandHandler('docs', docs)
    wiki_handler = CommandHandler('wiki', wiki)
    sandwich_handler = MessageHandler(Filters.regex(r'(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?'),
                                      sandwich)
    off_on_topic_handler = MessageHandler(Filters.regex(r'(?i)[\s\S]*?\b(?<!["\\])(off|on)[- _]?topic\b'),
                                          off_on_topic)

    # We need several matches so Filters.regex is basically useless
    # therefore we catch everything and do regex ourselves
    # This should probably be in another dispatcher group
    # but I kept getting SystemErrors...
    github_handler = MessageHandler(Filters.text, github)
    forward_faq_handler = MessageHandler(Filters.regex(r'(?i).*#faq.*'), forward_faq)

    dispatcher.add_handler(rate_limit_tracker_handler, group=-1)

    # Note: Order matters!
    taghints.register(dispatcher)
    dispatcher.add_handler(forward_faq_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(rules_handler)
    dispatcher.add_handler(rules_handler_hashtag)
    dispatcher.add_handler(docs_handler)
    dispatcher.add_handler(wiki_handler)
    dispatcher.add_handler(sandwich_handler)
    dispatcher.add_handler(off_on_topic_handler)
    dispatcher.add_handler(github_handler)

    inlinequeries.register(dispatcher)
    dispatcher.add_error_handler(error)

    updater.start_polling()
    logger.info('Listening...')

    try:
        github_issues.set_auth(config['KEYS']['github_client_id'], config['KEYS']['github_client_secret'])
    except KeyError:
        logging.info('No github auth set. Rate-limit is 60 requests/hour without auth.')

    github_issues.init_issues(dispatcher.job_queue)

    updater.idle()
Beispiel #3
0
def main():
    config = configparser.ConfigParser()
    config.read('bot.ini')

    updater = Updater(token=config['KEYS']['bot_api'])
    dispatcher = updater.dispatcher

    global SELF_CHAT_ID
    SELF_CHAT_ID = f'@{updater.bot.get_me().username}'

    start_handler = CommandHandler('start', start, pass_args=True)
    rules_handler = CommandHandler('rules', rules)
    rules_handler_hashtag = RegexHandler(r'.*#rules.*', rules)
    docs_handler = CommandHandler('docs', docs, allow_edited=True)
    wiki_handler = CommandHandler('wiki', wiki, allow_edited=True)
    sandwich_handler = RegexHandler(
        r'(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?',
        sandwich,
        pass_groups=True)
    off_on_topic_handler = RegexHandler(
        r'(?i)[\s\S]*?\b(?<!["\\])(off|on)[- _]?topic\b',
        off_on_topic,
        pass_groups=True)

    # We need several matches so RegexHandler is basically useless
    # therefore we catch everything and do regex ourselves
    # This should probably be in another dispatcher group
    # but I kept getting SystemErrors...
    github_handler = MessageHandler(Filters.all,
                                    github,
                                    allow_edited=True,
                                    pass_chat_data=True)
    forward_faq_handler = RegexHandler(r'(?i).*#faq.*', forward_faq)

    taghints.register(dispatcher)
    dispatcher.add_handler(forward_faq_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(rules_handler)
    dispatcher.add_handler(rules_handler_hashtag)
    dispatcher.add_handler(docs_handler)
    dispatcher.add_handler(wiki_handler)
    dispatcher.add_handler(sandwich_handler)
    dispatcher.add_handler(off_on_topic_handler)
    dispatcher.add_handler(github_handler)

    inlinequeries.register(dispatcher)
    dispatcher.add_error_handler(error)

    updater.start_polling()
    logger.info('Listening...')
    updater.idle()
Beispiel #4
0
def main():
    config = configparser.ConfigParser()
    config.read('bot.ini')

    updater = Updater(token=config['KEYS']['bot_api'])
    dispatcher = updater.dispatcher

    global SELF_CHAT_ID
    SELF_CHAT_ID = f'@{updater.bot.get_me().username}'

    start_handler = CommandHandler('start', start, pass_args=True)
    rules_handler = CommandHandler('rules', rules)
    rules_handler_hashtag = RegexHandler(r'.*#rules.*', rules)
    docs_handler = CommandHandler('docs', docs, allow_edited=True)
    wiki_handler = CommandHandler('wiki', wiki, allow_edited=True)
    sandwich_handler = RegexHandler(r'(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?', sandwich,
                                    pass_groups=True)
    off_on_topic_handler = RegexHandler(r'(?i)[\s\S]*?\b(?<!["\\])(off|on)[- _]?topic\b',
                                        off_on_topic,
                                        pass_groups=True)


    github_handler = MessageHandler(Filters.all, github, allow_edited=True, pass_chat_data=True)
    forward_faq_handler = RegexHandler(r'(?i).*#faq.*', forward_faq)

    taghints.register(dispatcher)
    dispatcher.add_handler(forward_faq_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(rules_handler)
    dispatcher.add_handler(rules_handler_hashtag)
    dispatcher.add_handler(docs_handler)
    dispatcher.add_handler(wiki_handler)
    dispatcher.add_handler(sandwich_handler)
    dispatcher.add_handler(off_on_topic_handler)
    dispatcher.add_handler(github_handler)

    inlinequeries.register(dispatcher)
    dispatcher.add_error_handler(error)

    updater.start_polling()
    logger.info('Listening...')

    try:
        github_issues.set_auth(config['KEYS']['github_client_id'], config['KEYS']['github_client_secret'])
    except KeyError:
        logging.info('No github auth set. Rate-limit is 60 requests/hour without auth.')

    github_issues.init_issues(dispatcher.job_queue)

    updater.idle()
Beispiel #5
0
def main() -> None:
    config = configparser.ConfigParser()
    config.read('bot.ini')

    defaults = Defaults(parse_mode=ParseMode.HTML,
                        disable_web_page_preview=True)
    updater = Updater(token=config['KEYS']['bot_api'], defaults=defaults)
    dispatcher = updater.dispatcher
    update_rules_messages(updater.bot)

    dispatcher.add_handler(MessageHandler(~Filters.command,
                                          rate_limit_tracker),
                           group=-1)

    # Note: Order matters!
    # Taghints - works with regex
    taghints.register(dispatcher)

    # Simple commands
    dispatcher.add_handler(CommandHandler('start', start))
    dispatcher.add_handler(CommandHandler('rules', rules))
    dispatcher.add_handler(MessageHandler(Filters.regex(r'.*#rules.*'), rules))
    dispatcher.add_handler(CommandHandler('docs', docs))
    dispatcher.add_handler(CommandHandler('wiki', wiki))
    dispatcher.add_handler(CommandHandler('help', help_callback))

    # Stuff that runs on every message with regex
    dispatcher.add_handler(
        MessageHandler(
            Filters.regex(r'(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?'),
            sandwich))
    dispatcher.add_handler(
        MessageHandler(
            Filters.regex(r'(?i)[\s\S]*?\b(?<!["\\])(off|on)[- _]?topic\b'),
            off_on_topic))
    # We need several matches so Filters.regex is basically useless
    # therefore we catch everything and do regex ourselves
    # This should probably be in another dispatcher group
    # but I kept getting SystemErrors..
    dispatcher.add_handler(
        MessageHandler(
            Filters.text & Filters.update.messages & ~Filters.command, github))

    # Status updates
    dispatcher.add_handler(
        ChatMemberHandler(greet_new_chat_members,
                          chat_member_types=ChatMemberHandler.CHAT_MEMBER))
    dispatcher.add_handler(
        MessageHandler(
            Filters.chat(username=[ONTOPIC_USERNAME, OFFTOPIC_USERNAME])
            & Filters.status_update.new_chat_members,
            delete_new_chat_members_message,
        ),
        group=1,
    )

    # Inline Queries
    inlinequeries.register(dispatcher)

    # Error Handler
    dispatcher.add_error_handler(error_handler)

    updater.start_polling(allowed_updates=Update.ALL_TYPES)
    logger.info('Listening...')

    try:
        github_issues.set_auth(config['KEYS']['github_client_id'],
                               config['KEYS']['github_client_secret'])
    except KeyError:
        logging.info(
            'No github api token set. Rate-limit is 60 requests/hour without auth.'
        )

    github_issues.init_ptb_contribs(
        dispatcher.job_queue)  # type: ignore[arg-type]
    github_issues.init_issues(dispatcher.job_queue)  # type: ignore[arg-type]

    # set commands
    updater.bot.set_my_commands([
        ('docs', 'Send the link to the docs. Use in private chat with rools.'),
        ('wiki', 'Send the link to the wiki. Use in private chat with rools.'),
        ('hints', 'List available tag hints. Use in private chat with rools.'),
        ('help',
         'Send the link to this bots README. Use in private chat with rools.'),
    ])

    updater.idle()
Beispiel #6
0
def main():
    config = configparser.ConfigParser()
    config.read('bot.ini')

    updater = Updater(token=config['KEYS']['bot_api'])
    dispatcher = updater.dispatcher

    global SELF_CHAT_ID
    SELF_CHAT_ID = f'@{updater.bot.get_me().username}'

    # dump requests list
    with open('resources/search.json', 'r') as file:
        main_list = json.load(file)
        requests_list = [
            each['value'] for each in main_list['body'][13]['block']['body'][0]
            ['expression']['right']['elements']
        ]
        types_list = [
            each['value'] for each in main_list['body'][13]['block']['body'][1]
            ['expression']['right']['elements']
        ]
        constructors_list = [
            each['value'] for each in main_list['body'][13]['block']['body'][2]
            ['expression']['right']['elements']
        ]
        requests_u_list = [
            each['value'] for each in main_list['body'][13]['block']['body'][3]
            ['expression']['right']['elements']
        ]
        types_u_list = [
            each['value'] for each in main_list['body'][13]['block']['body'][4]
            ['expression']['right']['elements']
        ]
        constructors_u_list = [
            each['value'] for each in main_list['body'][13]['block']['body'][5]
            ['expression']['right']['elements']
        ]
        all_list = {
            "Method": (requests_list, requests_u_list),
            "Type": (types_list, types_u_list),
            "Constructor": (constructors_list, constructors_u_list)
        }

    start_handler = CommandHandler('start', start, pass_args=True)
    rules_handler = CommandHandler('rules', rules)
    rules_handler_hashtag = RegexHandler(r'.*#rules.*', rules)
    docs_handler = CommandHandler('docs', docs, allow_edited=True)
    sandwich_handler = RegexHandler(
        r'(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?',
        sandwich,
        pass_groups=True)
    off_on_topic_handler = RegexHandler(
        r'(?i)[\s\S]*?\b(?<!["\\])(off|on)[- _]?topic\b',
        off_on_topic,
        pass_groups=True)

    # We need several matches so RegexHandler is basically useless
    # therefore we catch everything and do regex ourselves
    # This should probably be in another dispatcher group
    # but I kept getting SystemErrors...
    github_handler = MessageHandler(Filters.all,
                                    github,
                                    allow_edited=True,
                                    pass_chat_data=True)

    taghints.register(dispatcher)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(rules_handler)
    dispatcher.add_handler(rules_handler_hashtag)
    dispatcher.add_handler(docs_handler)
    dispatcher.add_handler(sandwich_handler)
    dispatcher.add_handler(off_on_topic_handler)
    dispatcher.add_handler(github_handler)

    inlinequeries.register(dispatcher, all_list)
    dispatcher.add_error_handler(error)

    updater.start_polling(clean=True)
    logger.info('Listening...')
    updater.idle()