def get_message_args(self, context: CommandContext): team_id = context.team_id user_id = context.event.user ts = time.time() redis = get_redis() last_poke_time_key = f"poke:last:{team_id}" user_count_key = f"poke:user:{team_id}" last_poke_user_key = f"poke:lastuser:{team_id}" last_poke_time = redis.get(last_poke_time_key) redis.set(last_poke_time_key, ts) last_poked_user_id = redis.get(last_poke_user_key) if last_poked_user_id: last_poked_user_id = last_poked_user_id.decode("utf-8") redis.set(last_poke_user_key, user_id) total_pokes = redis.hincrby(user_count_key, user_id) if last_poke_time is None: return { "icon_emoji": f"{Emoji.SHOOKCAT}", "text": ("You have poked meowbot 1 time!\n\n" "You're the first to poke meowbot!"), } s = "" if total_pokes == 1 else "s" last_poke = arrow.get(float(last_poke_time)).humanize() last_user = quote_user_id(last_poked_user_id) return { "icon_emoji": f"{Emoji.SHOOKCAT}", "text": f"You have poked meowbot {total_pokes} time{s}!\n\n" f"Meowbot was last poked {last_poke} by {last_user}", }
def get_message_args(self, context: CommandContext): team_id = context.team_id user_id = context.event.user ts = time.time() redis = get_redis() last_poke_time_key = f'poke:last:{team_id}' user_count_key = f'poke:user:{team_id}' last_poke_user_key = f'poke:lastuser:{team_id}' last_poke_time = redis.get(last_poke_time_key) redis.set(last_poke_time_key, ts) last_poked_user_id = redis.get(last_poke_user_key) if last_poked_user_id: last_poked_user_id = last_poked_user_id.decode('utf-8') redis.set(last_poke_user_key, user_id) total_pokes = redis.hincrby(user_count_key, user_id) if last_poke_time is None: return { 'icon_emoji': f'{Emoji.SHOOKCAT}', 'text': (f'You have poked meowbot 1 time!\n\n' 'You\'re the first to poke meowbot!') } s = '' if total_pokes == 1 else 's' last_poke = arrow.get(float(last_poke_time)).humanize() last_user = quote_user_id(last_poked_user_id) return { 'icon_emoji': f'{Emoji.SHOOKCAT}', 'text': f'You have poked meowbot {total_pokes} time{s}!\n\n' f'Meowbot was last poked {last_poke} by {last_user}' }
def get_message_args(self, context: CommandContext): text = "{} asked:\n>{}\n{}".format( quote_user_id(context.event.user), " ".join(context.args), random.choice(magic_eight_ball_options), ) return {"text": text, "icon_emoji": f"{Emoji.EIGHT_BALL}"}
def _parse_command(self): if not hasattr(self.event, 'text'): return None, None split_text = self.event.text.split(' ') quoted_bot_user = quote_user_id(self.bot_user) # If message starts with `@meowbot` if split_text[0] == quoted_bot_user: if len(split_text) > 1: _, command, *args = split_text else: return None, None # If message is direct IM, no `@meowbot` necessary elif self.event.channel_type == 'im': command, *args = split_text else: return None, None return (command.lower(), args)
def get_message_args(self, context: CommandContext): flavor = random.choice(list(Emoji.lacroix())) flavor_name = flavor.name.split('_')[0].capitalize() user = quote_user_id(context.event.user) return {'text': f'{user}: I recommend {flavor} {flavor_name} La Croix'}