Beispiel #1
0
async def activate_spy(message):
    table = SQLTable("events", conn)
    user = message.from_user

    events = await table.select(where=[
        f"id={message.from_user.id}",
        f"chatid={message.chat.id}"
    ])

    if len(events) == 0:
        table.insert(message.chat.id, user.id, user.full_name)
        await conn.commit()
    else:
        pass
Beispiel #2
0
async def rss_task(url, channelid, chatid):
    response = await aioget(url, timeout=3)

    try:
        text = await response.text()
    except asyncio.exceptions.TimeoutError:
        debug(f"[{channelid}] TimeoutError")
        return

    xml = feedparser.parse(text)
    first_video = xml["entries"][0]["link"]

    table = SQLTable("videos", conn)

    channels = await table.select(where=f"{channelid = }")

    if len(channels) == 0:
        await bot.send_message(chatid, first_video)
        await saveVideo(channelid, first_video)
    else:
        if first_video in json.loads(channels[0][1]):
            pass
        else:
            message = await bot.send_message(chatid, first_video)
            await bot.pin_chat_message(chatid,
                                       message.message_id,
                                       disable_notification=True)

            await saveVideo(channelid, first_video)

    await conn.commit()
Beispiel #3
0
async def saveVideo(channelid, link):
    table = SQLTable("videos", conn)
    table.quote = "'"

    links = await table.select(where=f"{channelid = }")

    try:
        links = json.loads(links[0][1])
        links.append(link)
    except IndexError:
        links = [link]

    links_str = json.dumps(links)

    await table.delete(where=f"{channelid = }")
    await table.insert(channelid, links_str)

    await conn.commit()
Beispiel #4
0
async def addNote(chatid, name, text):
    try:
        await removeNote(chatid, name)
    except Exception as e:
        print(e)

    table = SQLTable("notes", conn)

    await table.insert(chatid, name, text)
    await conn.commit()
Beispiel #5
0
async def calc_users(message):
    users = []
    table = SQLTable("events", conn)

    chat_users = await table.selectall(where=[f"chatid={message.chat.id}"])
    e = await table.select()

    for user in e:
        if user[1] in users:
            pass
        else:
            users.append(user[1])

    # В этом чяте <num> пользователей
    # Всего <num> пользователей

    text = "В этом чяте {} {}\nВсего {} {}"

    await message.reply(text.format(len(chat_users), _user_counter(chat_users),
                                    len(users), _user_counter(users)))
Beispiel #6
0
async def me_info(message):
    msg_template = (
        "*Full name:* {name}\n" +
        "*ID:* `{id}`\n\n" +
        "*Common chats*: `{chats}`\n" +
        "*User status*: {status}"
    )

    table = SQLTable("events", conn)
    chats = await table.select(where=[f"id={message.from_user.id}"])

    user = await bot.get_chat_member(
        message.chat.id,
        message.from_user.id
    )

    await message.reply(msg_template.format(
        name=message.from_user.full_name,
        id=message.from_user.id,
        chats=len(chats),
        status=user.status
    ), parse_mode="Markdown")
Beispiel #7
0
from sqlfocus import SQLTable

import datetime
from .config import conn

warns = SQLTable("warns", conn)


async def count_wtbans(user_id, chat_id, period=datetime.timedelta(hours=24)):
    period_bound = int((datetime.datetime.now() - period).timestamp())
    w = await warns.select(where=[
        f"timestamp >= {period_bound}", f"{user_id = }", f"{chat_id = }"
    ])

    return len(w)


async def mark_chat_member(user_id, chat_id, admin_id, reason):
    await warns.insert(user_id, admin_id, chat_id,
                       int(datetime.datetime.now().timestamp()), reason)

    await conn.commit()
Beispiel #8
0
    async def get_unique_users(self):
        users = []

        e = await self.select()

        for user in e:
            if user[1] in users:
                pass
            else:
                users.append(user[1])

        return users


events = Events(conn)
warns = SQLTable("warns", conn)
notes = SQLTable("notes", conn)
pidorstats = SQLTable("pidorstats", conn)


async def init_db():
    await events.create(exists=True,
                        schema=(("chatid", "INTEGER"), ("id", "INTEGER"),
                                ("name", "TEXT")))

    await warns.create(exists=True,
                       schema=(("user_id", "INTEGER"), ("admin_id", "INTEGER"),
                               ("chat_id", "INTEGER"),
                               ("timestamp", "INTEGER"), ("reason", "TEXT")))

    await notes.create(exists=True,
Beispiel #9
0
            except (exceptions.PollHasAlreadyBeenClosed,
                    exceptions.MessageWithPollNotFound):
                await self.delete(where=[
                    where, f"chat_id = {poll[0]}", f"poll_id = {poll[2]}"
                ])
                continue

            if poll_res.is_closed:
                await self.delete(where=where)
            else:
                await bot.stop_poll(poll[0], poll[2])


conn = asyncio.run(connect_db())

events = SQLTable("events", conn)
videos = Videos(conn)
warns = Warns(conn)
notes = SQLTable("notes", conn)
pidors = Pidors(conn)
pidorstats = SQLTable("pidorstats", conn)
polls = Polls(conn)


async def init_db():
    await events.create(exists=True,
                        schema=(("chatid", "INTEGER"), ("id", "INTEGER"),
                                ("name", "TEXT")))

    await videos.create(exists=True,
                        schema=(("channelid", "TEXT"), ("links", "TEXT")))
Beispiel #10
0
async def removeNote(chatid, name):
    table = SQLTable("notes", conn)
    await table.delete(where=[f"chatid={chatid}", f"name=\"{name}\""])

    await conn.commit()
Beispiel #11
0
async def showNotes(chatid):
    table = SQLTable("notes", conn)
    notes = await table.select(where=[f"chatid={chatid}"])

    return [item[1] for item in notes]
Beispiel #12
0
async def getNote(chatid, name):
    table = SQLTable("notes", conn)
    notes = await table.select(where=[f"chatid={chatid}", f'name="{name}"'])

    return notes[-1][-1]