Пример #1
0
def addPerson(update, context, name=None):

    if name is None:
        save_command(update, "add")

        if check_permission(update.message.from_user.id) > 1:
            context.bot.send_message(text=text.unauthorized,
                                     chat_id=update.message.chat_id)
            return

        try:
            sent_name = context.args[0]
        except IndexError:
            context.bot.send_message(chat_id=update.message.chat_id,
                                     text=text.validName)
            return
    else:
        sent_name = name

    with open(filePath, 'r+') as f_paste:
        paste_dict = json.load(f_paste)
        paste_dict.append(sent_name)
        f_paste.seek(0)
        json.dump(paste_dict, f_paste, indent=4)
        f_paste.truncate()

    try:
        chat = update.message.chat_id
    except:
        chat = getAVIS()

    context.bot.send_message(chat_id=chat,
                             text=text.personAdded.format(sent_name))

    showList(update, context)
Пример #2
0
def kick(update, context):
    save_command(update, "kick")
    if check_permission(update.message.from_user.id) > 0:
        context.bot.send_message(text=text.unauthorized, chat_id=update.message.chat_id)
        return

    try:
        people = getUserByFullName(context.args[0], context.args[1])
    except:
        message = text.args_not_given
        context.bot.send_message(text=message, chat_id=update.message.chat_id)
        return

    if not people:
        message = text.person_not_found.format(context.args[0], context.args[1])
        context.bot.send_message(text=message, chat_id=update.message.chat_id)
        return

    chat = fastChat.getAVIS()

    for person in people:
        try:
            context.bot.kick_chat_member(chat_id=chat, user_id=person.chat_id)
            context.bot.unban_chat_member(chat_id=chat, user_id=person.chat_id)
        except:
            message = text.can_not_kick.format(person.name + ' ' + person.surname, chat)
            context.bot.send_message(text=message, chat_id=update.message.chat_id)
Пример #3
0
def showList(update, context):

    try:
        save_command(update, "paste")
        if check_permission(update.message.from_user.id) > 2:
            context.bot.send_message(text=text.unauthorized,
                                     chat_id=update.message.chat_id)
            return
    except:
        print("no user id, may be an automatic call?")

    with open(filePath, 'r') as f_paste:
        paste_dict = json.load(f_paste)

    message = '\n'.join(paste_dict)

    try:
        chat = update.message.chat_id
    except:
        chat = getAVIS()

    if message == '':
        message = text.emptyList

    context.bot.send_message(chat_id=chat, text=message)
Пример #4
0
def checkBday(update, context):
    users = getUserBday()

    if len(users) != 0:

        context.bot.send_message(chat_id=getPRADA(), text="someone is happy")

        for user in users:

            if user.nickname is not None:
                name = user.nickname
            else:
                name = user.surname

            age = datetime.date.today().year - user.bday.year

            context.bot.send_message(chat_id=getAVIS(),
                                     text=happyBday.format(name, age))

            if user.active == 1:
                addPerson(update, context, name=name)

    else:
        context.bot.send_message(chat_id=getPRADA(), text="nobody is happy")