def cmd_unsub(bot, update, args, chat=None): if len(args) < 1: bot.reply(update, "Use /unsub username1 username2 username3 ...") return tw_usernames = args not_found = [] successfully_unsubscribed = [] for tw_username in tw_usernames: tw_user = bot.get_tw_user(tw_username) if tw_user is None or Subscription.select().where( Subscription.tw_user == tw_user, Subscription.tg_chat == chat).count() == 0: not_found.append(tw_username) continue Subscription.delete().where(Subscription.tw_user == tw_user, Subscription.tg_chat == chat).execute() successfully_unsubscribed.append(tw_user.full_name) reply = "" if len(not_found) is not 0: reply += "I didn't find any subscription to {}\n\n".format( ", ".join(not_found)) if len(successfully_unsubscribed) is not 0: reply += "You are no longer subscribed to {}".format( ", ".join(successfully_unsubscribed)) bot.reply(update, reply)
def cmd_unsub(update: telegram.Update, context: CallbackContext) -> None: args = context.args bot = context.bot chat, _created = TelegramChat.get_or_create( chat_id=update.message.chat.id, tg_type=update.message.chat.type, ) if len(args) < 1: bot.reply(update, "Use /unsub username1 username2 username3 ...") return tw_usernames = args not_found = [] successfully_unsubscribed = [] for tw_username in tw_usernames: tw_user = bot.get_tw_user(tw_username) if tw_user is None or Subscription.select().where( Subscription.tw_user == tw_user, Subscription.tg_chat == chat).count() == 0: not_found.append(tw_username) continue Subscription.delete().where(Subscription.tw_user == tw_user, Subscription.tg_chat == chat).execute() successfully_unsubscribed.append(tw_user.full_name) reply = "" if len(not_found) != 0: reply += "I didn't find any subscription to {}\n\n".format( ", ".join(not_found)) if len(successfully_unsubscribed) != 0: reply += "You are no longer subscribed to {}".format( ", ".join(successfully_unsubscribed)) bot.reply(update, reply)
def cmd_unChan(bot, update, args, chat=None): if len(args) < 2: bot.reply(update, "Use /unChan username1 channel") return tw_username = args[0] chatID = args[1] not_found = [] successfully_unsubscribed = [] tw_user = bot.get_tw_user(tw_username) newchat = TelegramChat.select().where(TelegramChat.chat_id == chatID) if newchat.count() == 0: bot.reply("chat not found") return if tw_user is None or Subscription.select().where( Subscription.tw_user == tw_user, Subscription.tg_chat == newchat[0]).count() == 0: not_found.append(tw_username) bot.reply("chat and user not found") return Subscription.delete().where(Subscription.tw_user == tw_user, Subscription.tg_chat == newchat[0]).execute() successfully_unsubscribed.append(tw_user.full_name) reply = "" if len(not_found) is not 0: reply += "I didn't find any subscription to {}\n\n".format( ", ".join(not_found)) if len(successfully_unsubscribed) is not 0: reply += "You are no longer subscribed to {}".format( ", ".join(successfully_unsubscribed)) bot.reply(update, reply)
def cmd_unsub(self, msg, args, chat=None): if len(args) < 1: self.reply(msg, "Use /unsub username1 username2 username3 ...") return tw_usernames = args not_found = [] successfully_unsubscribed = [] for tw_username in tw_usernames: tw_user = self.get_tw_user(tw_username) if tw_user is None or Subscription.select().where( Subscription.tw_user == tw_user, Subscription.tg_chat == chat).count() == 0: not_found.append(tw_username) continue Subscription.delete().where( Subscription.tw_user == tw_user, Subscription.tg_chat == chat).execute() successfully_unsubscribed.append(tw_user.full_name) reply = "" if len(not_found) is not 0: reply += "I didn't find any subscription to {}\n\n".format( ", ".join(not_found) ) if len(successfully_unsubscribed) is not 0: reply += "You are no longer subscribed to {}".format( ", ".join(successfully_unsubscribed) ) self.reply(msg, reply)