예제 #1
0
    def tell_leaderboard(self, msg: Message):
        logging.error(f'tell_leaderboard, {msg}')  # test for a while

        from_time = get_this_monday()
        text = _get_leaderboard_msg_text('本周排行榜',
                                         self.users,
                                         from_time=from_time)
        msg.say(text)
예제 #2
0
 def blocks(self, msg: Message):
     """blocks: show some rich messaging magic"""
     bx = [
         blocks.SectionBlock(
             text="*Markdown formatted* text with _italics_ if we want",
             fields=["*Left*", "*Right*", "line 2 left", "line 2 right"],
             accessory=elements.ImageElement(
                 image_url="http://placekitten.com/700/500",
                 alt_text="cute kitten"))
     ]
     msg.say("fallback", blocks=bx)
예제 #3
0
    def respond_to_command(self, msg: Message, arg: str):
        arg = arg or ''
        args = list(filter(None, [a.strip() for a in arg.split()]))
        try:
            arguments = docopt(self.__doc__, args)
        except DocoptExit as e:
            msg.say(e.usage, msg.thread_ts)
            return
        if arguments.get('-h') or arguments.get('--help'):
            msg.say(self.__doc__, msg.thread_ts)

        self.process_arguments(msg, arguments)
예제 #4
0
 def subcommand_invite(self, msg: Message, arguments: dict):
     msg.say('正在申请注册链接,请耐心等候...', msg.thread_ts)
     c = delegator.run('python commands/yuque.py invite',
                       cwd=os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
     if c.ok:
         msg.say(f'注册链接为: {c.out}', msg.thread_ts)
     else:
         msg.say(f'error: {c.err}', msg.thread_ts)
예제 #5
0
 def subcommand_add(self, msg: Message, arguments: dict):
     name = arguments.get('<name>')
     c = delegator.run(f'python commands/yuque.py add-to-tech-team {name}',
                       cwd=os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
     if c.ok:
         msg.say(f'已加入语雀技术组', msg.thread_ts)
     else:
         msg.say(f'加入语雀技术组出错', msg.thread_ts)
         msg.say(c.err, msg.thread_ts)
예제 #6
0
 def blocks_raw(self, msg: Message):
     """blocks raw: show some rich messaging magic. Uses raw dict for specifying blocks"""
     bx = [{
         "type": "section",
         "text": {
             "type":
             "mrkdwn",
             "text":
             "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
         }
     }, {
         "type": "divider"
     }, {
         "type":
         "section",
         "text": {
             "type":
             "mrkdwn",
             "text":
             "*Kin Khao*\n:star::star::star::star: 1638 reviews\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft."
         },
         "accessory": {
             "type": "image",
             "image_url":
             "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg",
             "alt_text": "alt text for image"
         },
         "fields": [{
             "type": "mrkdwn",
             "text": "*Priority*"
         }, {
             "type": "mrkdwn",
             "text": "*Type*"
         }, {
             "type": "plain_text",
             "text": "High"
         }, {
             "type": "mrkdwn",
             "text": "String"
         }]
     }, {
         "type": "section",
         "text": {
             "type":
             "mrkdwn",
             "text":
             "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
         },
         "accessory": {
             "type": "image",
             "image_url":
             "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
             "alt_text": "alt text for image"
         }
     }, {
         "type": "section",
         "text": {
             "type":
             "mrkdwn",
             "text":
             "*Ler Ros*\n:star::star::star::star: 2082 reviews\n I would really recommend the  Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder."
         },
         "accessory": {
             "type": "image",
             "image_url":
             "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg",
             "alt_text": "alt text for image"
         }
     }, {
         "type": "divider"
     }, {
         "type":
         "actions",
         "elements": [{
             "type": "button",
             "text": {
                 "type": "plain_text",
                 "text": "Farmhouse",
                 "emoji": True
             },
             "value": "click_me_123"
         }, {
             "type": "button",
             "text": {
                 "type": "plain_text",
                 "text": "Kin Khao",
                 "emoji": True
             },
             "value": "click_me_123"
         }, {
             "type": "button",
             "text": {
                 "type": "plain_text",
                 "text": "Ler Ros",
                 "emoji": True
             },
             "value": "click_me_123"
         }]
     }, {
         "type": "section",
         "text": {
             "type": "mrkdwn",
             "text": "You can add an image next to text in this block."
         },
         "accessory": {
             "type": "image",
             "image_url":
             "https://api.slack.com/img/blocks/bkb_template_images/plants.png",
             "alt_text": "plants"
         }
     }]
     msg.say("fallback", blocks=bx)
예제 #7
0
 def dm_scheduled(self, msg: Message):
     """dm reply scheduled: the bot replies to you at a later moment, in a DM"""
     msg.reply_dm("wait for it")
     dt = datetime.now() + timedelta(seconds=5)
     msg.reply_dm_scheduled(
         dt, "sure I'll reply to you in a DM after 5 seconds")
예제 #8
0
 def dm(self, msg: Message):
     """dm reply: the bot replies to you in a DM"""
     msg.reply_dm("sure I'll reply to you in a DM")
예제 #9
0
 def reply_me_in_thread(self, msg: Message):
     """reply in thread: the bot replies to you in a thread"""
     msg.reply("sure, I'll reply to you in a thread", in_thread=True)
예제 #10
0
 def reply_me_ephemeral(self, msg: Message):
     """reply ephemeral: the bot replies to you and only you can see it"""
     msg.reply("sure, I'll reply to you in an ephemeral message",
               ephemeral=True)
예제 #11
0
 def reply_me(self, msg: Message):
     """reply: the bot replies to you"""
     msg.reply("sure, I'll reply to you",
               icon_url="https://placekitten.com/200/200")
예제 #12
0
 def _gen_message(event, plugin_class_name):
     return Message(SlackClient(), event, plugin_class_name)
예제 #13
0
 def reply_help(self, msg: Message):
     msg.say(trim_doc(self.__doc__), msg.thread_ts)
예제 #14
0
 def _gen_message(self, event, plugin_class_name):
     return Message(MessagingClient(), event, plugin_class_name)