Ejemplo n.º 1
0
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import tracemoepy

from TamokutekiBot.helpers import command, format_bytes
from TamokutekiBot.plugins.graphql_queries import anime_search_query, manga_query

url = 'https://graphql.anilist.co'

tracemoe = tracemoepy.async_trace.Async_Trace(session=Tamokuteki.aio_session)


@Tamokuteki.on(command(pattern="anime", outgoing=True))
async def anime(event):
    search = event.text.split(' ', 1)
    if len(search) == 1:
        await event.edit("Format: .anime <anime name>")
        return
    else:
        search = search[1]
    variables = {'search': search}
    json = await (await session.post(url,
                                     json={
                                         'query': anime_search_query,
                                         'variables': variables
                                     })).json()
    if 'errors' in json.keys():
        await event.edit('No result found :(')
Ejemplo n.º 2
0
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from TamokutekiBot.helpers import command
from pathlib import Path
import re


@Tamokuteki.on(command(pattern="load"))
async def loading(event):
    reply = await event.get_reply_message()
    if reply:
        if reply.media and reply.media.document:
            if reply.media.document.mime_type == "text/x-python":
                path = await Tamokuteki.download_media(reply, "plugins/")
            else:
                await event.send("Reply to a valid file.")
                return
    else:
        if len((split := event.text.split(" ", 1))) == 1:
            await event.send("Reply to a plugin.")
            return
        path = split[1] + ".py"
        path = Path(__file__).parent / "plugins" / path
Ejemplo n.º 3
0
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from TamokutekiBot.helpers import command


@Tamokuteki.on(command(pattern="purge"))
async def purge(event):
    if not event.reply_to_msg_id:
        return
    split = event.text.split(" ", 1)
    if len(split) > 1 and split[1].isnumeric():
        purge_count = int(split[1])
    else:
        purge_count = None
    messages = []
    count = 0
    deleted = False
    async for message in Tamokuteki.iter_messages(
        event.chat_id, min_id=event.reply_to_msg_id, reverse=True
    ):
        if purge_count and count == purge_count:
Ejemplo n.º 4
0
from TamokutekiBot.helpers import command, format_bytes
import time
import asyncio


async def progress_message(current, total, _type, message, s) -> None:
    if time.time() - s % 10 == 0:
        total_size, total_type = format_bytes(total)
        curr_size, curr_type = format_bytes(total)
        await message.edit(
            f"{_type} {round(total_size, 2)} {total_type} out of {round(curr_size, 2)} {curr_type}"
        )


@Tamokuteki.on(command(pattern="download"))
async def download_file(event) -> None:
    if not event.is_reply:
        await event.send("Format: .download <As reply>")
        return
    reply = await event.get_reply_message()
    message = await event.reply(
        'Downloading...'
    )  # Not editing current message because if you edit current message with same content it will raise error while for this message it won't
    try:
        s = time.time()
        path = await Tamokuteki.download_media(
            reply,
            "Downloads/",
            progress_callback=lambda current, total: asyncio.get_event_loop(
            ).create_task(
Ejemplo n.º 5
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Thanks to https://github.com/rsktg or @TheRealPhoenix on telegram for the idea of getrep

from TamokutekiBot.helpers import command

import asyncio
import time


@Tamokuteki.on(command(pattern="alive", outgoing=True))
async def alive(event):
    await event.edit("I'm alive!")


@Tamokuteki.on(command(pattern="repo", outgoing=True))
async def repo(event):
    await event.edit(
        "Tamokuteki Bot\nRepo: https://github.com/DragSama/Tamokuteki")


@Tamokuteki.on(command(pattern="getrep", outgoing=True))
async def getrep(event):
    split = event.text.split(' ', 2)
    replied = await event.get_reply_message()
    if len(split) != 3 and not replied:
Ejemplo n.º 6
0
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from TamokutekiBot.helpers import command


@Tamokuteki.on(command(pattern="help"))
async def help(event) -> None:
    plugins = Tamokuteki.list_plugins()
    split = event.text.split(" ", 1)
    if len(split) == 1:
        plugin = "help"
    else:
        plugin = split[1]
    command = None
    if "/" in plugin:
        plugin, command = plugin.split("/")
    if plugin not in plugins:
        await event.edit("Plugin is not loaded or doesn't exist.")
        return
    mod = Tamokuteki.get_plugin(plugin)
    if not hasattr(mod, "__commands__"):
Ejemplo n.º 7
0
    async def get_settings():
        data = await COLLECTION.find_one({'type': 'lydia-settings'})
        return data

    async def update_settings(new_settings):
        await COLLECTION.replace_one(await get_settings(), new_settings)

    async def get_data():
        data = await get_settings()
        if not data:
            data = {'type': 'lydia-settings', 'users': {}}
            await COLLECTION.insert_one(data)
        return data

    @Tamokuteki.on(command(pattern="addchat", outgoing=True))
    async def addchat(event):
        settings = await get_data()
        reply_msg = await event.get_reply_message()
        if not reply_msg:
            await event.edit('Reply to a user to enable chatbot for it.')
            return
        user_id = reply_msg.sender_id
        if user_id in settings['users']:
            await event.edit("Chatbot is already enabled for this chat.")
            return
        session = lydia.create_session()
        settings['users'][str(user_id)] = {'expires_at': session.expires, 'session_id': session.id}
        await update_settings(settings)
        await event.edit('Enabled!')