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 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 #3
0
def operation(chat, message, query, data):
    d.execute('SELECT user FROM mess WHERE mesid=?', (message.id, ))
    users = d.fetchall()
    if users == [] or check2(users, query.sender.id):
        d.execute(
            'SELECT votes, userid, name, link FROM request WHERE mesid=?',
            (message.id, ))
        ex = d.fetchone()
        vote = ex[0] + int(data)
        userid = ex[1]
        # set how many votes are needed in default for the request to be approved up in line 52
        if vote >= int(r.get('votes')):
            good(chat, message, userid, None)
            message.edit(p["op"][0])
            d.execute('DELETE FROM mess WHERE mesid=?', (message.id, ))
            dat.commit()
            refreshpin(chat, message)
        elif vote <= -int(r.get('votes')):
            zero(chat, message, userid)
            message.edit(p["op"][1])
            d.execute('DELETE FROM mess WHERE mesid=?', (message.id, ))
            dat.commit()
            refreshpin(chat, message)
        else:
            d.execute('UPDATE request SET votes=? WHERE mesid=?',
                      (vote, message.id))
            d.execute('INSERT INTO mess (mesid, user) VALUES (?,?)',
                      (message.id, query.sender.id))
            dat.commit()
            query.notify(p["op"][2])
            qtvis(chat, message, userid)
    else:
        query.notify(p["op"][3])
Beispiel #4
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 #5
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 #6
0
def deletemine(message, chat):
    '''self-delete the request of the user'''
    if chat.type == "private":
        d.execute("SELECT stage FROM request WHERE userid=?",
                  (message.sender.id, ))
        try:
            stage = d.fetchone()[0]
        except TypeError:
            chat.send(p["deletemine"][0])
            return
        if stage == 0:
            return
        elif stage < 5:
            d.execute("DELETE FROM request WHERE userid=?",
                      (message.sender.id, ))
            dat.commit()
        elif stage == 5:
            d.execute("SELECT id FROM ids WHERE type=3")
            group = d.fetchone()[0]
            d.execute("SELECT mesid FROM request WHERE userid=?",
                      (message.sender.id, ))
            mesid = d.fetchone()[0]
            try:
                bot.edit_message(group, mesid, "Request canceled by user")
            except (TypeError, botogram.api.APIError):
                print(
                    "WARNING - You shall not delete the voting messages of an user"
                )
            d.execute("DELETE FROM request WHERE userid=?",
                      (message.sender.id, ))
            d.execute("DELETE FROM mess WHERE user=?", (message.sender.id, ))
            dat.commit()
        elif stage > 5:
            chat.send(p["deletemine"][1])
            return
        chat.send(p["deletemine"][2])
        refreshpin(chat, message)
Beispiel #7
0
def confirm(chat, message, data):
    '''confirm the request, and send it to the staff group'''
    door = int(r.get('door')) - 1
    r.set('door', door)
    bt = botogram.Buttons()
    d.execute('UPDATE request SET stage=4 WHERE userid=?', (chat.id, ))
    dat.commit()
    d.execute("SELECT id FROM ids WHERE type=1")
    staffs = d.fetchone()
    bt[0].callback(p["confirm"][0], "refuse", str(chat.id))
    bt[1].callback(p["confirm"][1], "good", str(chat.id))
    bt[2].callback(p["confirm"][2], "vote", str(chat.id))
    for group in staffs:
        bot.chat(group).send(staffvis(str(chat.id)), attach=bt)
    message.edit(p["confirm"][3])
Beispiel #8
0
def qtvis(chat, message, data):
    '''a cute indentation for the message with the votes in the user's group'''
    d.execute("SELECT * FROM request WHERE userid=?", (int(data), ))
    ex = d.fetchone()
    name = ex[0]
    lnk = ex[1]
    userid = int(data)
    nameuser = ex[4]
    ur = ex[6]
    vote = ex[7]
    bt = botogram.Buttons()
    bt[0].callback('+1', 'op', str(+1))
    bt[0].callback('-1', 'op', str(-1))
    message.edit(p["qtvis"] % (ur, nameuser, userid, name, lnk, vote),
                 preview=False,
                 attach=bt)
Beispiel #9
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 #10
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 #11
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 #12
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
Beispiel #13
0
import botogram
import sqlite3
import os
import time
from obj.start import r, d, dat, logch
from obj.jsonr import p
from obj.visualizers import visualizer, staffvis, verdict
from obj.checks import checklink, check2, knowit, checkperm
bot = botogram.create(p["values"]["token"])
# Set your api token in the json file (data/lang.json)$
bot.owner = "@Mamiglia & https://github.com/Mamiglia/Requester-Bot"
# Set yourself as the owner$

d.execute("SELECT id FROM ids WHERE type=3")
x = d.fetchone()
if x is not None:
    bot.chat(int(x[0])).send('Admins, press /refreshpin!')


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, ))