Exemplo n.º 1
0
def update_cache(bot: Bot, update: Update):
    msg = core.get_message(update)
    user = msg.from_user
    # Also skip first update when the bot is added
    if not core.is_private(msg.chat_id) and core.chat_users.get(
            msg.chat_id) is not None:
        core.chat_users[msg.chat_id].update({user.id: core.get_name(user)})
Exemplo n.º 2
0
def change_spin_name(bot: Bot, update: Update, args: list):
    msg = core.get_message(update) #why fudg1n' upd4t3s m8!?
    if core.can_change_name(can_change_name, msg.chat_id, msg.from_user.id):
        spin = " ".join(args)
        if spin == None:
            spin = config.DEFAULT_SPIN_NAME
        spin_name[msg.chat_id] = spin
        msg.reply_text(text=f"Текст розыгрыша изменён на *{spin} дня*", parse_mode=ParseMode.MARKDOWN)
    else:
        return
Exemplo n.º 3
0
def admin_shell(bot: Bot, update: Update, args: list):
    msg = core.get_message(update)
    try:
        cmd = args.pop(0)
    except IndexError:
        return
    if cmd == "exec":
        exec(" ".join(args))
    elif cmd == "vardump":
        bot.send_message(chat_id=msg.chat_id, text="```\n{}\n```".format(eval(" ".join(args))), 
                         parse_mode=ParseMode.MARKDOWN, reply_to_message_id=msg.message_id)
    elif cmd == "reset":
        reset(bot, None)
Exemplo n.º 4
0
def change_spin_name(bot: Bot, update: Update, args: list):
    msg = core.get_message(update)
    if len(args) == 0:
        spin = core.spin_name.get(msg.chat_id, config.DEFAULT_SPIN_NAME)
        msg.reply_text(text=f"Текущее название розыгрыша: *{spin} дня*",
                       parse_mode=ParseMode.MARKDOWN)
        return
    if core.can_change_spin_name(msg.chat_id, msg.from_user.id, bot):
        if args[-1].lower() == "дня" and len(args) > 1:
            args.pop(-1)
        spin = " ".join(args)
        core.spin_name[msg.chat_id] = spin
        msg.reply_text(text=f"Текст розыгрыша изменён на *{spin} дня*",
                       parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 5
0
def admin_ctrl(bot: Bot, update: Update, args: list):
    msg = core.get_message(update)
    reply = msg.reply_to_message
    admins = core.get_admins_ids(bot, msg.chat_id)
    admins.append(config.BOT_CREATOR)
    is_admin = msg.from_user.id in admins
    if len(args) == 0:
        return
    cmd = args.pop(0)
    if msg.chat_id not in core.can_change_name:
        core.can_change_name[msg.chat_id] = []
    if cmd == "add" and reply and is_admin:
        if core.can_change_spin_name(msg.chat_id, reply.from_user.id, bot):
            msg.reply_text(
                text=
                "Этот пользователь *уже может* изменять название розыгрыша",
                parse_mode=ParseMode.MARKDOWN)
        else:
            core.can_change_name[msg.chat_id].append(reply.from_user.id)
            msg.reply_text(
                text=
                "Теперь этот пользователь *может* изменять название розыгрыша",
                parse_mode=ParseMode.MARKDOWN)
    elif cmd == "del" and reply and is_admin:
        if not core.can_change_spin_name(msg.chat_id, reply.from_user.id, bot):
            msg.reply_text(
                text=
                "Этот пользователь *ещё не может* изменять название розыгрыша",
                parse_mode=ParseMode.MARKDOWN)
        else:
            index = core.can_change_name[msg.chat_id].index(reply.from_user.id)
            core.can_change_name[msg.chat_id].pop(index)
            msg.reply_text(
                text=
                "Теперь этот пользователь *не может* изменять название розыгрыша",
                parse_mode=ParseMode.MARKDOWN)
    elif cmd == "list":
        text = "Пользователи, которые *могут* изменять название розыгрыша (не считая администраторов):\n```\n"
        for user in core.can_change_name[msg.chat_id]:
            text += core.chat_users[msg.chat_id].get(user, f"id{user}") + '\n'
        text += "```"
        msg.reply_text(text, parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 6
0
def auto_spin_config(bot: Bot, update: Update, args: list,
                     job_queue: JobQueue):
    msg = core.get_message(update)
    if len(args) == 0:
        return
    is_moder = core.can_change_spin_name(msg.chat_id, msg.from_user.id, bot)
    cmd = args.pop(0)
    if cmd == "set" and is_moder:
        try:
            time = args[0].split(':')
            time = "{:0>2}:{:0>2}".format(time[0], time[1])
            job = Job(auto_spin, 86400.0, context=msg.chat_id)
            job_queue.put(job, next_t=core.time_diff(time))
            if msg.chat_id in core.auto_spins:
                core.auto_spin_jobs[msg.chat_id].schedule_removal()
        except (ValueError, IndexError):
            msg.reply_text(
                f"Ошибка! Проверьте время на правильность и отредактируйте сообщение"
            )
            return

        core.auto_spins.update({msg.chat_id: time})
        core.auto_spin_jobs.update({msg.chat_id: job})
        msg.reply_text(
            f"Автоматический розыгрыш установлен на {time} GMT+0\n\n"
            f"ВНИМАНИЕ! Если розыгрыш уже был проведён до того, как запустится автоматический розыгрыш, то"
            f" бот не напишет ничего в чат по наступлению времени розыгрыша")
    elif cmd == 'del' and is_moder:
        if msg.chat_id in core.auto_spins:
            core.auto_spin_jobs.pop(msg.chat_id).schedule_removal()
            core.auto_spins.pop(msg.chat_id)
            msg.reply_text(
                "Теперь автоматический розыгрыш отключен в этом чате")
        else:
            msg.reply_text(
                "Автоматический розыгрыш ещё не был включен в этом чате")
    elif cmd == 'status':
        if msg.chat_id in core.auto_spins:
            msg.reply_text(f"Автоматический розыгрыш установлен в этом чате"
                           f" на {core.auto_spins.get(msg.chat_id)} GMT+0")
        else:
            msg.reply_text("Автоматический розыгрыш отключен в этом чате")
Exemplo n.º 7
0
def admin_shell(bot: Bot, update: Update, args: list):
    msg = core.get_message(update)
    if msg.from_user.id != config.BOT_CREATOR:
        log.debug(
            f"Attempted to use '{msg.text}' by {core.get_name(msg.from_user)}")
        return

    try:
        cmd = args.pop(0)
    except IndexError:
        return
    if cmd == "exec":
        exec(" ".join(args))
    elif cmd == "vardump":
        bot.send_message(chat_id=msg.chat_id,
                         text="```\n{}\n```".format(eval(" ".join(args))),
                         parse_mode=ParseMode.MARKDOWN,
                         reply_to_message_id=msg.message_id)
    elif cmd == "reset":
        reset(bot, None)
    elif cmd == "respin":
        log.info(f"Respin done in '{msg.chat.title}' ({msg.chat_id})")
        core.results_today.pop(msg.chat_id)
        msg.reply_text("respin ok")
    elif cmd == "md_announce":
        core.announce(bot, " ".join(args), md=True)
    elif cmd == "announce":
        core.announce(bot, " ".join(args))
    elif cmd == "sendlogs":
        with open(config.LOG_FILE, 'rb') as f:
            msg.reply_document(f)
    elif cmd == "help":
        msg.reply_text(
            "Help:\nexec — execute code\nvardump — print variable's value\n"
            "reset — reset all spins\nrespin — reset spin in this chat\n"
            "md_announce — tell something to all chats (markdown is on)\n"
            "announce — tell something to all chats (markdown is off)\n"
            "sendlogs — send latest logs as document")
Exemplo n.º 8
0
def update_cache(bot: Bot, update: Update):
    msg = core.get_message(update)
    user = msg.from_user
    if not core.is_private(msg.chat_id):
        chat_users[msg.chat_id].update({user.id: core.get_name(user)})