def insert_user(username, firstname): get_user = User.objects.all().filter(user_name=username) if get_user.exists(): get_user.update(calls=F("calls") + 1) else: user = User(user_name=username, first_name=firstname, calls=1) user.save()
def process__users(self, update, command, params): users = list(User.select()) usernames = map(lambda x: "@%s" % x.username, users) usernames = sorted(usernames) usernames = ", ".join(usernames) text = "*Total %s users:*" % User.select().count() self.send(chat_id=update.message.chat_id, text=text, parse_mode=telegram.ParseMode.MARKDOWN) self.send(chat_id=update.message.chat_id, text=usernames)
def process__op(self, update, command, params): chat_id = update.message.chat_id if params: params = params.replace(' ', '').lower() params = params[1:] if params.startswith('@') else params user, _ = User.get_or_create(username=params) user.is_admin = True user.save() self.bot.sendMessage(chat_id=chat_id, text="Added permissions for @%s" % params) else: moderators = User.select().where(User.is_admin==True) moderators = map(lambda x: "@%s" % x.username, moderators) moderators = sorted(moderators) moderators = ", ".join(moderators) self.bot.sendMessage(chat_id=chat_id, text="*Admins:*\r\n", parse_mode=telegram.ParseMode.MARKDOWN) self.bot.sendMessage(chat_id=chat_id, text=moderators or '--------')
def process__m(self, update, command, params): admins = User.select().where(User.is_admin==True) for admin in admins: if admin.chat_id != update.user.chat_id: self.send(chat_id=admin.chat_id, text=u"Сообщение от @%s" % update.user.username) self.send(chat_id=admin.chat_id, text=u"Текст сообщения: :%s" % params) self.send(chat_id=update.message.chat_id, text=u"Ваше сообщение принято.")
def _process_get_user(self, update, command, params): from_user = update.message.from_user user, _ = User.get_or_create(username=from_user.username, chat_id=update.message.chat_id) user.first_name = from_user.first_name user.last_name = from_user.last_name user.chat_id = update.message.chat_id user.save() update.user = user
def _process_none(self, update, command, params): chat_id = update.message.chat_id users = list(User.select().where(User.listen==True)) for user in users: if user.chat_id != chat_id: self.send(chat_id=user.chat_id, text=u"@%s сообщил:\r\n%s" %(unicode(update.message.from_user.username), unicode(params)), photo=update.message.photo[3].file_id if update.message.photo else None)
def process__deop(self, update, command, params): chat_id = update.message.chat_id params = params.replace(' ', '').lower() params = params[1:] if params.startswith('@') else params moderator = User.select().where(User.username==params) if moderator.count(): moderator[0].is_admin = False moderator[0].save() self.bot.sendMessage(chat_id=chat_id, text="Removed permissions for @%s" % params)
def process__sorry(self, update, command, params): if not update.user.banned: self.send(chat_id=update.message.chat_id, text=u"Вы не забанены") else: admins = User.select().where(User.is_admin==True) for admin in admins: self.send(chat_id=admin.chat_id, text=u"Заявка на разбан от @%s" % update.user.username) self.send(chat_id=admin.chat_id, text=u"Текст заявки: %s" % unicode(params)) self.send(chat_id=update.message.chat_id, text=u"Ваша заявка принята.")
def process__unban(self, update, command, params): chat_id = update.message.chat_id if params: params = params.replace(' ', '').lower() params = params[1:] if params.startswith('@') else params users = list(User.select().where(User.username==params)) if users: user = users[0] user.banned = False user.save() self.bot.sendMessage(chat_id=chat_id, text="Unbanned @%s" % params) else: users = list(User.select().where(User.banned==True)) users = sorted(map(lambda x: "@%s" % x.username, users)) users = ', '.join(users) text = "*Total banned users - %s:*" % User.select().where(User.banned==True).count() self.send(chat_id=update.message.chat_id, text=text, parse_mode=telegram.ParseMode.MARKDOWN) self.bot.sendMessage(chat_id=chat_id, text=users or '-------')
def process__ban(self, update, command, params): chat_id = update.message.chat_id params = params.replace(' ', '').lower() params = params[1:] if params.startswith('@') else params users = list(User.select().where(User.username==params)) if users and users[0].username != settings.MAIN_ADMIN and not users[0].is_admin: user = users[0] user.banned = True user.save() self.bot.sendMessage(chat_id=chat_id, text="Banned @%s" % params)