当前位置: 首页>>代码示例>>Python>>正文


Python Scheduler.schedule_job方法代码示例

本文整理汇总了Python中Scheduler.Scheduler.schedule_job方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.schedule_job方法的具体用法?Python Scheduler.schedule_job怎么用?Python Scheduler.schedule_job使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scheduler.Scheduler的用法示例。


在下文中一共展示了Scheduler.schedule_job方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Scheduler import Scheduler [as 别名]
# 或者: from Scheduler.Scheduler import schedule_job [as 别名]

#.........这里部分代码省略.........
        self.register_command('lenny', LennyFaceHandler.LennyFaceHandler(self.bot).handle,
                              help='Finds and displays a random Lenny Face.')
        self.register_command('roll', RollHandler.RollHandler(self.bot).handle,
                              help='Rolls Y X-sided dice with the phrasing !roll YdX')
        self.register_command('translate', TranslateHandler.TranslateHandler(self.bot).handle,
                              help='Translates a phrase from one language to another. \nUse   '
                                     ' phrase|from_language|to_language \n'
                                     'OR phrase|to_language to translate to another language and trust in language auto-detection\n'
                                     'OR just phrase if you want to translate to English and still trust auto-detection. \n')
        wolfram_alpha_api_token = self.bot.config.get('Authentication', 'wolfram_alpha_api_token')
        self.wolfram_alpha_client = WolframAlphaClient(wolfram_alpha_api_token)
        self.register_command('wolfram',
                              WolframBasicQuery.WolframAlphaBasicQueryHandler(self.bot,
                                                                              self.wolfram_alpha_client).handle,
                              help='Queries WolframAlpha!')
        imgur_id = self.bot.config.get('Authentication', 'imgur_client_id')
        imgur_secret = self.bot.config.get('Authentication', 'imgur_client_secret')
        self.imgur_client = ImgurClient(imgur_id, imgur_secret)
        self.register_command('dankify',
                              Dankify.Dankify(self.bot, self.imgur_client).handle,
                              help='Can be used to produce a dankified image! \n'
                                   'Use: !dankify [url]')

        print('Bot started')

    def register_command(self, command_string, message_handler, help=None,
                         admin_only=False, enable_independent=False):
        self.command_dict[command_string] = message_handler

        if not admin_only:
            self.help_dict[command_string] = help

        if admin_only:
            self.command_admin_permission[command_string] = admin_only
        else:
            self.command_admin_permission[command_string] = False

        if enable_independent:
            self.command_enable_permission[command_string] = enable_independent
        else:
            self.command_enable_permission[command_string] = False

    def handle(self, msg):
        time_stamp_str = msg.xml.attrib['ts'].split('.')[0]
        time_stamp = long(time_stamp_str)

        if time_stamp < self.last_msg:
            return None
        elif msg['type'] == 'groupchat':
            # self.last_msg = time_stamp
            message_body = msg['body']
            from_name_full = msg['mucnick']
            split_str = message_body.split(' ')

            if len(split_str[0]) <= len(COMMAND_CHAR) or not split_str[0].startswith(COMMAND_CHAR):
                return None

            command = split_str[0].replace(COMMAND_CHAR, "", 1)

            handler = self.command_dict[command]
            admin_permission = self.command_admin_permission[command]
            enable_independent_permission = self.command_enable_permission[command]

            if handler is None or \
                    (admin_permission and not from_name_full == self.bot.user_nickname) or \
                    (not enable_independent_permission and not self.enable_bot):
                return None

            reply_msg = handler(split_str, from_name_full, msg)

            print("command %s by %s" % (command, from_name_full))

            if reply_msg is not None:
                self.bot.reply_room(msg, reply_msg)

    def enable_bot_cmd(self, message, from_name_full, msg_obj):
        self.enable_bot = True
        return "Functions Enabled"

    def disable_bot_cmd(self, message, from_name_full, msg_obj):
        self.enable_bot = False
        return "Functions Disabled"

    def join_cmd(self, message, from_name_full, msg_obj):
        room_name = ' '.join(message[1:])
        if self.bot.join_room_by_name(room_name):
            self.bot.reply_room(msg_obj, "Joining room '%s'" % room_name)
        else:
            self.bot.reply_room(msg_obj, "Could not find room")

    def help_cmd(self, message, from_name_full, msg_obj):
        returned_message = ""
        for help_message in self.help_dict.items():
            returned_message = returned_message + help_message[0] + ' : ' + help_message[1] + '\n'
        return returned_message

    def remindme_cmd(self, message, from_name_full, msg_obj):
        remind_date_text = ' '.join(message[1:])
        self.scheduler.schedule_job(remind_date_text,
                                    RemindMeHandler.RemindMeHandler(self.bot, from_name_full, msg_obj).job)
开发者ID:JeffBorwey,项目名称:HypeBot,代码行数:104,代码来源:MessageHandler.py


注:本文中的Scheduler.Scheduler.schedule_job方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。