Exemplo n.º 1
0
def callback_handler(bot, update):
    try:
        query = update.callback_query
        uid = update.callback_query.from_user.id
        cid = query.message.chat_id
        user = "******" + str(query.from_user.username)
        data = query.data.split(" ")
        a = query.message.text.split("\n")[0].split(" ")
        a = "<b>%s</b> %s %s <b>%s %s</b>" % tuple(a)
        message = a + "\n" + query.message.text.split("\n")[1]
        expired = False
        if user == "@None":
            bot.sendMessage(chat_id=cid,
                            text=texter("warning02", SETTINGS["LENGUAGE"]),
                            parse_mode=telegram.ParseMode.HTML)
        elif data[0] == "JG":  # Joint group
            info = SquadManager.join(user, uid, data[1], True)
        elif data[0] == "LG":  # Leave group
            info = SquadManager.leave(user, data[1])
        elif data[0] == "UG":  # Undecided group
            info = SquadManager.join(user, uid, data[1], False)
        if not info and user != "@None":
            bot.edit_message_text(chat_id=query.message.chat_id,
                                  message_id=query.message.message_id,
                                  text=texter("warning01",
                                              SETTINGS["LENGUAGE"]),
                                  parse_mode=telegram.ParseMode.HTML)
        elif user != "@None":
            send_create_group(bot, cid, message, data[2], query, data[1])

    except Exception as e:
        print(e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)
Exemplo n.º 2
0
def command_create_squad(bot, update, args=[], chat_data=True, job_queue=True):
    try:
        cid = update.message.chat_id
        uid = update.message.from_user.id
        user = "******" + str(update.message.from_user.username)
        a = args_time(args)
        if user == "@None":
            bot.sendMessage(chat_id=cid,
                            text=texter("warning02", SETTINGS["LENGUAGE"]),
                            parse_mode=telegram.ParseMode.HTML)
        elif a:
            info = SquadManager.create_squad(user, cid)
            if info == "try_again":
                message = texter("squad02", SETTINGS["LENGUAGE"]) % (user)
                bot.sendMessage(chat_id=cid,
                                text=message,
                                parse_mode=telegram.ParseMode.HTML)
            else:
                a = (a[0], a[1], user)
                message = texter("squad01", SETTINGS["LENGUAGE"]) % a
                sent = send_create_group(bot, cid, message, user)
                job = job_queue.run_once(expire_group, 172800, context=cid)
                SquadManager.to_register_job(cid, sent.message_id, job, info)
        else:
            message = texter("squad03", SETTINGS["LENGUAGE"])
            sent = bot.sendMessage(chat_id=cid,
                                   text=message,
                                   parse_mode=telegram.ParseMode.HTML)
            SquadManager.add_message_id(sent.message_id, cid)
            job_queue.run_once(expire_message, 45, context=cid)
    except Exception as e:
        print(e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)
Exemplo n.º 3
0
def command_eliminate(bot, update, chat_data=True):
    cid = update.message.chat_id
    mid = update.message.reply_to_message.message_id
    user = "******" + str(update.message.from_user.username)
    if user in SETTINGS["SUPERUSERS"]:
        SquadManager.delete_group_job(cid, mid)
        bot.sendMessage(chat_id=cid,
                        text=texter("warning03", SETTINGS["LENGUAGE"]),
                        parse_mode=telegram.ParseMode.HTML)
Exemplo n.º 4
0
def send_create_group(bot, cid, message, user, query=False, group=False):
    s_list = "\n"
    if not group:
        group = SquadManager.get_group(user)
    users = SquadManager.get_group_users(group)
    data = " %s %s" % (group, user)
    sym1 = texter("symbol01", SETTINGS["LENGUAGE"])
    sym2 = texter("symbol02", SETTINGS["LENGUAGE"])
    sym3 = texter("symbol03", SETTINGS["LENGUAGE"])
    sym4 = texter("symbol04", SETTINGS["LENGUAGE"])
    count = 0
    for user in users:
        if user[0] is not None:
            count += 1
            if user[2]:
                s = sym2 + " " + user[0] + "\n"
            else:
                s = sym3 + " " + user[0] + "\n"
        else:
            s = sym1 + "\n"
        s_list += s
    message += "\n" + sym4 % (count, len(users))
    message += s_list
    a = [[
        telegram.InlineKeyboardButton(text=texter("btn_group_01",
                                                  SETTINGS["LENGUAGE"]),
                                      callback_data="JG" + data)
    ],
         [
             telegram.InlineKeyboardButton(text=texter("btn_group_02",
                                                       SETTINGS["LENGUAGE"]),
                                           callback_data="LG" + data)
         ],
         [
             telegram.InlineKeyboardButton(text=texter("btn_group_03",
                                                       SETTINGS["LENGUAGE"]),
                                           callback_data="UG" + data)
         ]]
    keyboard = telegram.InlineKeyboardMarkup(a)
    if query:
        sent = bot.edit_message_text(chat_id=query.message.chat_id,
                                     message_id=query.message.message_id,
                                     text=message,
                                     parse_mode=telegram.ParseMode.HTML,
                                     reply_markup=keyboard)
        return sent
    else:
        sent = bot.sendMessage(chat_id=cid,
                               text=message,
                               parse_mode=telegram.ParseMode.HTML,
                               reply_markup=keyboard)
        SquadManager.add_group_message_id(cid, sent.message_id, group)
        return sent
Exemplo n.º 5
0
def command_refloat(bot, update, chat_data=True):
    try:
        cid = update.message.chat_id
        mid = update.message.reply_to_message.message_id
        text = update.message.reply_to_message.text
        a = text.split("\n")[0].split(" ")
        a = "<b>%s</b> %s %s <b>%s %s</b>" % tuple(a)
        u = text.split("\n")[1]
        message = a + "\n" + u
        user = text.split("\n")[1].split(" ")[2]
        group = SquadManager.get_group_message_id(cid, mid)
        if group:
            bot.delete_message(chat_id=cid, message_id=mid)
            sent = send_create_group(bot, cid, message, user, False, group)
            SquadManager.repalace_job_id(cid, sent.message_id, cid, mid)
        else:
            bot.sendMessage(chat_id=cid,
                            text=texter("warning01", SETTINGS["LENGUAGE"]),
                            parse_mode=telegram.ParseMode.HTML)
    except Exception as e:
        print(e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)
Exemplo n.º 6
0
def command_help(bot, update, pass_chat_data=True):
    cid = update.message.chat_id
    bot.sendMessage(chat_id=cid,
                    text=texter("help", SETTINGS["LENGUAGE"]),
                    parse_mode=telegram.ParseMode.HTML)