Beispiel #1
0
def resizevotes(message, chat):
    '''command for Admins only, resize the number of votes that a request need to be approved'''
    if checkperm(message.sender.id):
        try:
            r.set('votes', int(message.text[12::]))
            chat.send("Votes that a request needs to be approved are now %s" %
                      (int(r.get('votes'))))
        except ValueError:
            chat.send("Insert a valid number!")
Beispiel #2
0
def changereqnum(message, chat):
    '''command for Admins only, change the number of requests that will be accepted, set to 0 to close the requests'''
    if checkperm(message.sender.id):
        try:
            r.set('door', int(message.text[5::]))
            chat.send('Now I\'m open to %s requests' % (int(r.get('door'))))
        except ValueError:
            chat.send(
                'Actually still open to %s requests, Insert a valid number' %
                (int(r.get('door'))))
Beispiel #3
0
def unblock(message, chat):
    '''command for Admins only, unblock an user'''
    if chat.type == "private" and checkperm(message.sender.id):
        bt = botogram.Buttons()
        d.execute("SELECT userid, name FROM request WHERE stage=0")
        blocklist = d.fetchall()
        if blocklist == []:
            chat.send("There aren't blocked users")
        else:
            for index, user in enumerate(blocklist):
                bt[index].callback(str(user[1]), "unban", str(user[0]))
            chat.send("Who do you want to unblock?", attach=bt)
Beispiel #4
0
def deletereq(message, chat):
    '''command for Admins only, delete the request of a user. Type: /delete @username'''
    if checkperm(message.sender.id):
        username = message.text[9::].lower()
        print(username)
        d.execute("SELECT name FROM request WHERE username=?", (username, ))
        b = d.fetchone()
        if b is not None:
            d.execute("DELETE FROM request WHERE username=?", (username, ))
            dat.commit()
            chat.send("Deleted >:c")
        else:
            chat.send("Invalid Username")
Beispiel #5
0
def backup_db(chat, message):
    '''command for Admins only, send the request's db to backup it'''
    if checkperm(message.sender.id):
        chat.send_file(path="data/dat1.db",
                       caption=("Backup from %s" % (time.ctime())))
        d.execute("SELECT count(*) FROM request")
        active_req = d.fetchone()[0]
        d.execute("SELECT count(*) FROM mess")
        being_voted = d.fetchone()[0]
        d.execute("SELECT count(*) FROM request WHERE stage=6")
        to_do_reqs = d.fetchone()[0]
        chat.send(
            "Active requests: %s\nBeing Voted Requests: %s\nApproved Request to do: %s"
            % (active_req, being_voted, to_do_reqs))
Beispiel #6
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 #7
0
def cleanreq(message, chat):
    '''command for Admins only, clean all the requests'''
    if checkperm(message.sender.id):
        chat.send('cleaning..')
        d.execute("DROP TABLE IF EXISTS request")
        d.execute("DROP TABLE IF EXISTS mess")
        d.execute("VACUUM")
        d.execute(
            "CREATE TABLE IF NOT EXISTS request (name TEXT, link TEXT, userid INTEGER PRIMARY KEY, username TEXT, nameuser TEXT, stage INTEGER DEFAULT 1, type TEXT, votes INTEGER DEFAULT 0, mesid INTEGER)"
        )
        d.execute(
            'CREATE TABLE IF NOT EXISTS mess (mesid INTEGER, user INTEGER)')
        chat.send('Done!')
        dat.commit()
Beispiel #8
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 #9
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 #10
0
def cleanall(message, chat):
    '''command for Admins only, clean everything (also the database with the admins and groups)'''
    if checkperm(message.sender.id):
        chat.send('cleaning..')
        d.execute("DROP TABLE IF EXISTS request")
        d.execute("DROP TABLE IF EXISTS mess")
        d.execute("DROP TABLE IF EXISTS ids")
        d.execute("VACUUM")
        d.execute(
            "CREATE TABLE IF NOT EXISTS request (name TEXT, link TEXT, userid INTEGER PRIMARY KEY, username TEXT, nameuser TEXT, stage INTEGER DEFAULT 1, type TEXT, votes INTEGER DEFAULT 0, mesid INTEGER)"
        )
        d.execute(
            "CREATE TABLE IF NOT EXISTS ids (id INTEGER PRIMARY KEY, username TEXT, type INTEGER)"
        )
        d.execute(
            'CREATE TABLE IF NOT EXISTS mess (mesid INTEGER, user INTEGER)')
        dat.commit()
        chat.send('all proofs cleared ;)')
Beispiel #11
0
def adminhelp(message, chat):
    '''command only for Admins, help admins to understand what actions they can do'''
    if checkperm(message.sender.id):
        chat.send("These are the commands that only an admin can perform:\n\
-/newadmin Your_password : set you as a new admin\n\
-/refreshpin : refresh and pin the message in public group, if you reply to a message: the text of the messagge will be included in the pin\n\
\n\
-/door N : change the number of requests that the bot can have\n\
-/resizevotes N : resize the number of votes that a request needs to have to be accepted\n\
\n\
-/setstaff : type in the staff group to set the staff group\n\
-/setgroup : type in your group to set it\n\
-/setlog @(your channel username): set your log channel, reboot is needed\n\
\n\
-/block : block an user, first send this command, and then forward a message of the user\n\
-/unblock : a list of the blocked users, click one to unblock\n\
-/delete @username: delete the user's request\n\
\n\
-/cleanreq : delete all the requests\n\
-/sqldb : execute a command on the SQL tables (SQLite3)\n\
-/backup : backup the actual requester db (SQLite3)")
Beispiel #12
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!")