def iscrivi(bot, update): i = 0 chatid = update.message.chat_id userid = update.message.from_user.id chat_type = bot.get_chat(chatid) if chat_type.type != "private": admin = bot.get_chat_administrators(chatid) for user_id in admin: if user_id.user.id != userid: i = i else: i = i + 1 if i == 0: bot.sendMessage(update.message.chat_id, text = NOTADMINERROR) else: if supporto.findUserId(chatid) == 1: msg = "Sei già iscritto!" bot.sendMessage(update.message.chat_id, text=msg) else: text = supporto.RESTCall("latest") supporto.addUserId(chatid) bot.sendMessage(update.message.chat_id, text=SUBSCRIBEOK) bot.sendMessage(update.message.chat_id, text=text['text'], parse_mode=telegram.ParseMode.HTML) else: if supporto.findUserId(chatid) == 1: msg = "Sei già iscritto!" bot.sendMessage(update.message.chat_id, text=msg) else: text = supporto.RESTCall("latest") supporto.addUserId(chatid) bot.sendMessage(update.message.chat_id, text=SUBSCRIBEOK) bot.sendMessage(update.message.chat_id, text=text['text'], parse_mode=telegram.ParseMode.HTML)
def filtra(bot, update, args): text = supporto.RESTCall("categorylist") cat = list() for t in text['text'].split('\n')[1:]: cat.append(t) try: if args[0].lower() in cat[:-1]: text = supporto.RESTCall("category", args[0].lower()) bot.sendMessage(update.message.chat_id, text['text'], parse_mode=telegram.ParseMode.HTML) except: bot.sendMessage(update.message.chat_id, INVALIDCAT)
def send_update(bot, update): id = supporto.readLastEvent() users = supporto.getChatId() if users == 0: return text = supporto.RESTCall("all", id) if (text['maxid'] > id): for u in users: try: bot.sendMessage(chat_id=u, text=text['text'], parse_mode=telegram.ParseMode.HTML) time.sleep(0.03) except Unauthorized: print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ": Unauthorized: User " + u + " removed") supporto.setUserForRemove(u) supporto.removeUsers() supporto.setLastEvent(text['maxid']) print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ": Update Send")
def categorie(bot, update): text = supporto.RESTCall("categorylist") bot.sendMessage(update.message.chat_id, text['text'])
def ultime(bot, update): text = supporto.RESTCall("latest") bot.sendMessage(update.message.chat_id, text=NEWSHEADER) bot.sendMessage(update.message.chat_id, text=text['text'], parse_mode=telegram.ParseMode.HTML)