def rf(update: Update, context: CallbackContext): logging.debug(context.args) if len(context.args) > 0: context.args[0] = '4df+' + str(context.args[0]) else: context.args = ['4df'] process(update, context)
def subscribe(self, update: Update, context: CallbackContext): if len(context.args) == 0: context.args = [self.birbs_subreddit] chat = str(update.message.chat_id) config = ConfigObj(self.conf_file) if cache_subscriptions not in config: config[cache_subscriptions] = {} config.write() config.reload() if chat not in config[cache_subscriptions]: config[cache_subscriptions][chat] = [] config.write() config.reload() for subreddit in context.args: if subreddit not in config[cache_subscriptions][chat]: chat_subs = config[cache_subscriptions][chat] chat_subs.append(subreddit) config.write() config.reload() print(f'Subscribtion of {subreddit} for chat {chat}') context.bot.send_message( chat_id=update.message.chat_id, text= f'Subscription successful! Sending an image from {subreddit} every hour' ) else: context.bot.send_message( chat_id=update.message.chat_id, text=f'You are already subscribed to {subreddit}!')
def nextgame_start(update: Update, context: CallbackContext): user_id = update.effective_user.id database.insert_player_pm(user_id, True) context.args = context.args[0].split("_") if context.args else None if not context.args or context.args[0] != "nextgame": return try: chat_id = int(context.args[1]) new_id = database.get_new_id(chat_id) if new_id: chat_id = new_id lang = database.get_language_chat(chat_id) except ValueError: context.bot.send_message(user_id, get_string("en", "group_not_found")) return chat_details = database.get_group_title(chat_id) chat_link = helpers.chat_link(chat_details["title"], chat_details["link"]) new = database.insert_group_nextgame(chat_id, user_id) if new: context.bot.send_message(user_id, get_string( lang, "nextgame_added").format(chat_link), parse_mode=ParseMode.HTML, disable_web_page_preview=True) else: context.bot.send_message( user_id, get_string(lang, "nextgame_removed").format(chat_link), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def test_slot_behaviour(self, cdp, recwarn, mro_slots): c = CallbackContext(cdp) for attr in c.__slots__: assert getattr(c, attr, 'err') != 'err', f"got extra slot '{attr}'" assert not c.__dict__, f"got missing slot(s): {c.__dict__}" assert len(mro_slots(c)) == len(set(mro_slots(c))), "duplicate slot" c.args = c.args assert len(recwarn) == 0, recwarn.list
def handle_update( self, update: HandlerArg, dispatcher: Dispatcher, check_result: object, context: CallbackContext = None, ): """Handle update.""" optional_args = self.collect_optional_args(dispatcher, update) context.args = optional_args return self.callback(update, context)
def start(update: Update, context: CallbackContext): user_id = update.effective_user.id database.insert_player_pm(user_id, True) user_data = context.user_data if "lang" not in user_data: lang = database.get_language_player(user_id) user_data["lang"] = lang else: lang = user_data["lang"] context.args = context.args[0].split("_") if context.args else None if not context.args or context.args[0] != "settings": return # not necessary, but pycharm won't believe me that... chat_id = 0 try: chat_id = int(context.args[1]) chat = context.bot.get_chat(chat_id) except ValueError: context.bot.send_message(user_id, get_string(lang, "group_not_found")) return except BadRequest: try: new_id = database.get_new_id(chat_id) if new_id: chat = context.bot.get_chat(int(new_id)) else: raise BadRequest except BadRequest: context.bot.send_message(user_id, get_string(lang, "group_not_found")) return database.insert_group_title(chat_id, chat.title, chat.link) if not helpers.is_admin(context.bot, update.effective_user.id, chat): update.effective_message.reply_text( get_string(lang, "no_admin_settings")) return buttons = group_settings_helpers.group_settings_buttons( get_string(lang, "group_setting_buttons"), chat_id) chat_link = helpers.chat_link(chat.title, chat.link) context.bot.send_message(user_id, get_string( lang, "group_setting_text").format(chat_link), reply_markup=InlineKeyboardMarkup(buttons), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def delete_job_conv(update: Update, context: CallbackContext): query = update.callback_query job = context.user_data[SELECTED_JOB] remove_job( context, query.message.chat_id, job ) del context.user_data[SELECTED_JOB] query = update.callback_query context.bot.answer_callback_query( query.id, text=emojize('Job deleted', use_aliases=True) ) context.args = {'job_type': JOB_TO_CHAT_DATA_KEY[job.name]} return choose_job_conv(update, context)
def check_rise_fall_day(context: CallbackContext) -> NoReturn: chat_data = context.job.context.dispatcher.chat_data datetime_now = datetime.now() date_now = datetime_now.date() datetime_zero = datetime.fromtimestamp(0) for c_id, cd in chat_data.items(): stonks = cd.get(conf.INTERNALS['stock'], {}) chat_custom = Chat(c_id, 'group') message_custom = Message(0, datetime_now, chat=chat_custom) update_custom = Update(0, message=message_custom) msg_daily = get_daily_dict(cd) daily_rise = msg_daily[conf.JOBS['check_rise_fall_day']['dict'] ['rise']] daily_fall = msg_daily[conf.JOBS['check_rise_fall_day']['dict'] ['fall']] for symbol, stonk in stonks.items(): msg_last_rise_at = daily_rise.get(symbol, datetime_zero).date() msg_last_fall_at = daily_fall.get(symbol, datetime_zero).date() context.args = [symbol] if msg_last_rise_at == date_now and msg_last_fall_at == date_now: continue res_calc = stonk.calculate_perf_rise_fall_daily() to_send_message = [] if res_calc: if stonk.daily_rise.calculated_at.date( ) == date_now and msg_last_rise_at < date_now: if stonk.daily_rise.percent >= conf.JOBS[ 'check_rise_fall_day']['threshold_perc_rise']: text = f"🚀🚀🚀 {stonk.name} ({stonk.symbol}) is rocketing to " \ f"{round_currency_scalar(stonk.daily_rise.price)} " \ f"{conf.LOCAL['currency']} (+{stonk.daily_rise.percent.round(2)}%)" to_send_message.append(text) daily_rise[symbol] = datetime_now if stonk.daily_fall.calculated_at.date( ) == date_now and msg_last_fall_at < date_now: if stonk.daily_fall.percent <= conf.JOBS[ 'check_rise_fall_day']['threshold_perc_fall']: text = f"📉📉📉 {stonk.name} ({stonk.symbol}) is drow" \ f"ning to {round_currency_scalar(stonk.daily_fall.price)} " \ f"{conf.LOCAL['currency']} ({stonk.daily_fall.percent.round(2)}%)" to_send_message.append(text) daily_fall[symbol] = datetime_now for message in to_send_message: try: send_message(context, c_id, message) chart(update_custom, context, reply=False, symbols=[stonk.symbol]) except error.Unauthorized: error_message = f'Rise/Fall check: User ID {c_id} blocked our bot. Thus, this user was will ' \ f'be removed from chat_data.' error_handler(update_custom, context, error_message) del context.job.context.dispatcher.chat_data[c_id] break
def show(self, update: Update, context: CallbackContext) -> bool: """显示目前操作中的卡片的信息。私聊时默认显示游戏外的卡,群聊时优先显示游戏内的卡。 (如果有多张卡,用`/switch`切换目前操作的卡。) `/show`:显示最基础的卡片信息; `/show card`:显示当前操作的整张卡片的信息; `/show --attrname`:显示卡片的某项具体属性。 (回复某人消息)`/show card或--attrname`:同上,但显示的是被回复者的卡片的信息。 例如,`/show skill`显示主要技能, `/show interest`显示兴趣技能。 如果要显示主要技能点和兴趣技能点,请使用`mainpoints`, `intpoints`作为`arg`,而不要使用points。 如果当前卡中没有这个属性,则无法显示。 可以显示的属性例子: `STR`,`description`,`SAN`,`MAGIC`,`name`,`item`,`job`""" pl = self.forcegetplayer(update) rppl = self.getreplyplayer(update) rpcard: Optional[GameCard] = None if rppl is None and len(context.args) > 0: if isint(context.args[0]): rppl = self.getplayer(int(context.args[0])) if rppl is not None: context.args = context.args[1:] if rppl is not None: gp = self.forcegetgroup(update) rpcard = self.findcardfromgroup(rppl, gp) if rpcard is None: return self.errorInfo("该玩家在本群没有卡") card = rpcard if rpcard is not None else None if card is None: if isgroup(update): gp = self.forcegetgroup(update) card = self.findcardfromgroup(pl, gp) if card is None: return self.errorInfo("请先在本群创建卡") else: card = pl.controlling if card is None: return self.errorInfo("请先创建卡,或者使用 /switch 选中一张卡") game = card.group.game if card.group.game is not None else card.group.pausedgame rttext = "" if game is not None and isgroup(update): if card.id in game.cards: rttext = "显示游戏中的卡:\n" card = game.cards[card.id] if rttext == "": rttext = "显示游戏外的卡:\n" if not self.checkaccess(pl, card) & CANREAD: return self.errorInfo("没有权限") if card.type != PLTYPE and isgroup(update): return self.errorInfo("非玩家卡片不可以在群内显示") if len(context.args) == 0: self.reply(card.basicinfo()) return True if context.args[0] == "card": self.reply(str(card)) return True if context.args[0] == "mainpoints": ans = card.skill.show("points") elif context.args[0] == "intpoints": ans = card.interest.show("points") elif context.args[0] == "points": return self.errorInfo("请用mainpoints或intpoints来显示") else: ans = card.show(context.args[0]) if ans == "找不到该属性": return self.errorInfo("找不到该属性") if ans == "": self.reply(rttext + "无") else: self.reply(rttext + ans) return True
def rf(update: Update, context: CallbackContext): if len(context.args) > 0: context.args[0] = '4df+' + str(context.args[0]) else: context.args = ['4df'] roll(update, context)
def back_to_choose_job_conv(update: Update, context: CallbackContext): job = context.user_data[SELECTED_JOB] context.args = {'job_type': JOB_TO_CHAT_DATA_KEY[job.name]} return choose_job_conv(update, context)