Beispiel #1
0
def groupvote(chat, message, data, query):
    '''the request will be voted in the group'''
    d.execute("SELECT stage FROM request WHERE userid=?", (int(data), ))
    x = d.fetchone()
    try:
        if x[0] == 4:
            try:
                bot.chat(int(data)).send(p["vote"])
            except botogram.ChatUnavailableError as e:
                message.delete()
                if e == "blocked":
                    chat.send("The user has blocked the Bot. Request canceled")
                elif e == "account_deleted":
                    chat.send("The user deleted its account. Request canceled")
                else:
                    chat.send("User unavailable: %s" % (e))
                d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
                dat.commit()
        else:
            message.edit("Already in another Stage baby")
    except TypeError:
        dat.rollback()
        message.edit(p["alreadydel"])
    else:
        d.execute('UPDATE request SET stage=5 WHERE userid=?', (int(data), ))
        dat.commit()
        message.edit(
            verdict(int(data), 'vote', query.sender.name, query.sender.id))
        d.execute("SELECT id FROM ids WHERE type=3")
        groups = d.fetchone()
        bt = botogram.Buttons()
        bt[0].callback('start', 'startpoll', data)
        for group in groups:
            bot.chat(group).send("New Poll by %s" % (data), attach=bt)
Beispiel #2
0
def good(chat, message, data, query):
    '''Accept the request without voting procedure'''
    d.execute("SELECT stage FROM request WHERE userid=?", (int(data), ))
    try:
        stage = int(d.fetchone()[0])
        if stage <= 5:
            d.execute('UPDATE request SET stage=6 WHERE userid=?',
                      (int(data), ))
            dat.commit()
            bt = botogram.Buttons()
            bt[0].callback(p["good"][1], 'zero2', str(data))
            if stage == 4:
                message.edit(
                    verdict(int(data), True, query.sender.name,
                            query.sender.id))
                try:
                    bot.chat(int(data)).send(p["good"][0])
                except botogram.ChatUnavailableError as e:
                    message.delete()
                    chat.send("User unavailable: %s" % (e))
                    d.execute("DELETE FROM request WHERE userid=?",
                              (int(data), ))
                    dat.commit()
                else:
                    logch.send(staffvis(data), attach=bt)
            else:
                logch.send(staffvis(data), attach=bt)
        else:
            message.edit("Already in another Stage baby")
    except TypeError:
        dat.rollback()
        message.edit(p["alreadydel"])
Beispiel #3
0
def executesql(chat, message):
    if chat.type == 'private':
        if checkperm(message.sender.id):
            comm = message.text[6::]
            print(
                "\nINFO - This command was executed by %s:" %
                (message.sender.name), comm, "\n")
            try:
                d.execute(comm)
                chat.send(str(d.fetchall()))
                dat.commit()
            except sqlite3.OperationalError:
                dat.rollback()
                chat.send("Can't accept this command")
Beispiel #4
0
def blockuser(message, chat):
    '''command for Admins only, block an user'''
    if chat.type == "private" and checkperm(message.sender.id):
        bt = botogram.Buttons()
        bt[0].callback("Cancel", "delete")
        chat.send(
            "Now forward a message from the user that you would like to block",
            attach=bt)
        try:
            d.execute("INSERT INTO request (userid, stage) VALUES (?, 99)",
                      (message.sender.id, ))
            dat.commit()
        except sqlite3.IntegrityError:
            dat.rollback()
            d.execute("UPDATE request SET stage=99 WHERE userid=?",
                      (message.sender.id, ))
            dat.commit()
Beispiel #5
0
def refuse(chat, message, query, data):
    '''refuse the request'''
    d.execute("SELECT stage FROM request WHERE userid=?", (int(data), ))
    try:
        if d.fetchone()[0] == 4:
            message.edit(
                verdict(int(data), False, query.sender.name, query.sender.id))
            d.execute("DELETE FROM request WHERE userid=?", (int(data), ))
            dat.commit()
            try:
                bot.chat(int(data)).send(p["refuse"])
            except Exception:
                pass
        else:
            message.edit("Already in another Stage baby")
    except TypeError:
        dat.rollback()
        message.edit(p["alreadydel"])
Beispiel #6
0
def setgroup(chat, message):
    '''command for Admins only, set the group where are the users, and the group where the requests will be voted'''
    if chat.type == "supergroup":
        if checkperm(message.sender.id):
            try:
                d.execute("INSERT INTO ids (id, type) VALUES (?,?)",
                          (chat.id, 3))
                chat.send("Group correctly set!")
                dat.commit()
            except sqlite3.IntegrityError:
                dat.rollback()
                chat.send("This Chat is already been used for something else")
        else:
            chat.send(
                "I need to receive the command from an important guy, not a console peasant as you"
            )
    else:
        chat.send("I should be in a Supergroup, wrong chat!")
Beispiel #7
0
def checkreq(cht, typ):
    '''Check if the user can make a request, the users can have only one request at time'''
    if int(r.get('door')) > 0:
        try:
            d.execute("INSERT INTO request (userid, type) VALUES (?,?)",
                      (cht.id, typ))
            dat.commit()
            return True
        except sqlite3.IntegrityError:
            dat.rollback()
            d.execute("SELECT stage FROM request WHERE userid=?", (cht.id, ))
            if d.fetchone()[0] == 0:
                cht.send(p["checkreq"][2])
            else:
                cht.send(p["checkreq"][0])
    else:
        cht.send(p["checkreq"][1])
    return False
Beispiel #8
0
def setlogchannel(chat, message):
    '''command for Admins only, set the log channel'''
    if chat.type == "private":
        if checkperm(message.sender.id):
            chn = message.text[8::]
            try:
                global logch
                logch = botogram.channel(chn, p["values"]["token"])
                d.execute("INSERT INTO ids (username, type) VALUES (?,?)",
                          (chn, 2))
                chat.send("Log Channel correctly set! Reboot me")
                dat.commit()
            except botogram.api.ChatUnavailableError:
                dat.rollback()
                chat.send('Username invalid')
        else:
            chat.send(
                "I need to receive the command from an important guy, not a console peasant as you"
            )
    else:
        chat.send("I should be in a private chat, wrong chat!")
Beispiel #9
0
def newadmin(chat, message):
    '''Insert a new admin in the admins list, remember to set your password in lang.json $$'''
    if p["values"]["password"] in message.text:
        d.execute("SELECT id FROM ids WHERE type=0")
        if d.fetchone() is None:
            d.execute("INSERT INTO ids (id, type) VALUES (?,?)",
                      (bot.itself.id, 0))
            dat.commit()
        try:
            d.execute("INSERT INTO ids (id, type) VALUES (?,?)",
                      (message.sender.id, 0))
            chat.send("W-welcome home S-Senpai!")
            chat.send(
                "You already know what you what to do with me, right?\nIn any case, if you don't have any idea check it here /adminhelp"
            )
            dat.commit()
        except sqlite3.IntegrityError:
            dat.rollback()
            chat.send(
                "You are already an admin UwU, you can't become adminer than this"
            )
    else:
        chat.send("Who is this CONSOLE-PEASANT??")
Beispiel #10
0
def stager(chat, message):
    '''The core of this code, it just checks at what moment the request is, and ask the specific information to the user'''
    if chat.type == "private":
        d.execute("SELECT stage FROM request WHERE userid=?", (chat.id, ))
        try:
            stage = int(d.fetchone()[0])
            if stage == 1:
                bot.edit_message(chat, int(message.id - 1), p["request"][1])
                bt = botogram.Buttons()
                d.execute(
                    "UPDATE request SET stage=2, name=?, username=?, nameuser=? WHERE userid=?",
                    (
                        message.text,
                        (message.sender.username).lower(),
                        message.sender.name,
                        chat.id,
                    ))
                dat.commit()
                bt[0].callback(p["stager"]["1"][1], "rename")
                bt[1].callback(p["stager"]["1"][2], 'void')
                chat.send(p["stager"]["1"][3], attach=bt)
            elif stage == 2:
                try:
                    d.execute("SELECT link FROM request WHERE userid=?",
                              (chat.id, ))
                    # selection due to the fact that i use the same stager() function also in the 'No Link' event
                    lnk = d.fetchone()[0]
                    if lnk is None:
                        lnk = str(message.parsed_text.filter("link")[0])
                        res = checklink(lnk)
                        bot.edit_message(chat, int(message.id - 1),
                                         p["stager"]["1"][3])
                    else:
                        lnk = 'No link'
                        res = True
                        message.edit(p["stager"]["1"][3])
                        chat.send(p["stager"]["2"][5])
                    if res:
                        bt = botogram.Buttons()
                        d.execute(
                            "UPDATE request SET link=?, stage=3 WHERE userid=?",
                            (lnk, chat.id))
                        dat.commit()
                        bt[0].callback(p["stager"]["2"][1], "relink",
                                       str(chat.id))
                        bt[1].callback(p["stager"]["2"][2], "zero",
                                       str(chat.id))
                        bt[1].callback(p["stager"]["2"][3], 'confirm',
                                       str(chat.id))
                        chat.send(visualizer(chat),
                                  syntax="markdown",
                                  attach=bt)
                    else:
                        chat.send(p["stager"]["2"][4])
                except IndexError:
                    dat.rollback()
                    chat.send(p["stager"]["2"][4])
            elif stage == 3:
                chat.send(p["stager"]["3"][0])
            elif stage == 4:
                chat.send(p["stager"]["4"][0])
            elif stage == 5:
                chat.send(p["stager"]["5"][0])
            elif stage == 6:
                chat.send(p["stager"]["6"][0])
            elif stage == 0:
                chat.send(p["stager"]["0"][0])
            elif stage == 99:
                blocking = message.forward_from
                print(blocking.name)
                try:
                    d.execute(
                        "INSERT INTO request (userid, name, stage) VALUES (?,?,0)",
                        (blocking.id, blocking.name))
                except sqlite3.IntegrityError:
                    dat.rollback()
                    d.execute("UPDATE request SET stage=0 WHERE userid=?",
                              (blocking.id, ))
                d.execute("DELETE FROM request WHERE userid=?",
                          (message.sender.id, ))
                dat.commit()
                chat.send("BLOCKED, type /unblock to unblock ")
            else:
                chat.send(p["stager"]["err"][0])
        except TypeError:
            chat.send(knowit(int(r.get('door'))))
        dat.commit()
        return True