Exemplo n.º 1
0
    from gc import get_stats as get_gc_stats

try:
    import psutil
except ModuleNotFoundError:
    psutil = None

from datetime import datetime
from threading import enumerate as list_threads, _MainThread as MainThreadType

from hata import eventlist, EventThread, KOKORO, ExecutorThread, chunkify, Embed, Color, elapsed_time, Future, sleep
from hata.ext.commands import Command, checks, Pagination

from bot_utils.models import DB_ENGINE

STAT_COMMANDS = eventlist(type_=Command, category='STATS')
STAT_COLOR = Color.from_rgb(61, 255, 249)

def setup(lib):
    category = Koishi.command_processer.get_category('STATS')
    if (category is None):
        Koishi.command_processer.create_category('STATS', checks=[checks.owner_only()])
    
    Koishi.commands.extend(STAT_COMMANDS)

def teardown(lib):
    Koishi.commands.unextend(STAT_COMMANDS)

@STAT_COMMANDS.from_class
class threads:
    async def command(client, message):
Exemplo n.º 2
0
# -*- coding: utf-8 -*-
from random import choice, randint

from hata import Color, Embed, eventlist, DiscordException, parse_emoji, CLIENTS, BUILTIN_EMOJIS, ERROR_CODES
from hata.ext.commands import Command, wait_for_message, ConverterFlag, Converter, wait_for_reaction, Closer

GAMES_COLOR = Color.from_rgb(148, 0, 211)
GAMES_COMMANDS = eventlist(type_=Command)


def setup(lib):
    Koishi.commands.extend(GAMES_COMMANDS)


def teardown(lib):
    Koishi.commands.unextend(GAMES_COMMANDS)


@GAMES_COMMANDS.from_class
class message_me:
    async def command(client, message):
        channel = await client.channel_private_create(message.author)
        try:
            await client.message_create(channel, 'Love you!')
        except DiscordException as err:
            if err.code == ERROR_CODES.invalid_message_send_user:
                await client.message_create(
                    message.channel,
                    'Pls turn on private messages from this server!')

    category = 'GAMES'
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
from hata import DiscordException,  cchunkify, Status, EXTRA_EMBED_TYPES, Embed, Task, Color, eventlist, Permission, \
    listdifference, ActivityChange, KOKORO
from hata.discord.parsers import EVENTS, DEFAULT_EVENT
from hata.ext.prettyprint import pretty_print
from hata.ext.commands import Pagination, Command
from hata.backend.utils import method

DISPATCH_TESTS = eventlist(type_=Command)
DISPTACH_COLOR = Color.from_rgb(120, 108, 128)

def setup(lib):
    main_client.commands.extend(DISPATCH_TESTS)
    
def teardown(lib):
    main_client.commands.unextend(DISPATCH_TESTS)

class dispatch_tester:
    channel = None
    old_events = {}

    @classmethod
    async def here(self,client, message):
        if message.channel is self.channel:
            try:
                await client.message_create(message.channel, 'Current channel removed')
            except DiscordException:
                return
            self.channel = None
        else:
            try:
import os
import subprocess

from hata import eventlist, Embed, alchemy_incendiary
from hata.events import ContentParser, Pagination
from hata.extension_loader import ExtensionError

commands = eventlist()


def OIDs():
    return [
        207188318130012160, 300126997718237195, 524288464422830095,
        562086061153583122
    ]


@commands(case='cog-list')
async def list_of_cogs(client, message, content):
    cogs = []
    for i in os.listdir(os.path.join('cogs', 'hata')):
        if i.endswith('.py'):
            cogs.append(i[:-3])
    pages = []
    part = []
    index = 0
    for element in cogs:
        if index == 15:
            pages.append('\n'.join(part))
            part.clear()
            index = 0
Exemplo n.º 5
0
# -*- coding: utf-8 -*-
import sys

from hata import CLIENTS, USERS, GUILDS, CHANNELS, Embed, eventlist, Client, __version__
from hata.ext.commands import Command, checks, Converter, ConverterFlag, Closer
from bots.koishi import KOISHI_HELP_COLOR, DUNGEON_INVITE, DUNGEON, WORSHIPPER_ROLE, EVERYNYAN_ROLE, \
    ANNOUNCEMNETS_ROLE, WELCOME_CHANNEL

from bot_utils.shared import KOISHI_GIT, HATA_GIT, DUNGEON_INVITE, DUNGEON, HATA_DOCS, TORTOISE_PASTE

HELP_COMMANDS = eventlist(type_=Command)


def setup(lib):
    Koishi.commands.extend(HELP_COMMANDS)


def teardown(lib):
    Koishi.commands.unextend(HELP_COMMANDS)


@HELP_COMMANDS.from_class
class about:
    async def command(client, message):
        implement = sys.implementation
        embed = Embed('About', f'Hello, I am {client.full_name} as you expected. What did you think, who am I?',
                color=KOISHI_HELP_COLOR) \
            .add_field('Library', f'[hata {__version__}]({HATA_GIT})', inline=True) \
            .add_field('Interpreter', (
                f'Python{implement.version[0]}.{implement.version[1]}'
                f'{"" if implement.version[3]=="final" else " "+implement.version[3]} {implement.name}'
Exemplo n.º 6
0
from hata import eventlist, BUILTIN_EMOJIS

CAKE = BUILTIN_EMOJIS['cake']

cute_commands = eventlist()


@cute_commands
async def cake(client, message):
    await client.message_create(message.channel, CAKE.as_emoji)


@cute_commands(name='love')
async def send_love(client, message):
    channel = await client.channel_private_create(message.author)
    await client.message_create(channel, 'I love you :3')
Exemplo n.º 7
0

async def teardown(lib):
    for client in CLIENTS:
        client.events.remove(load_auto_react_roles, 'ready', by_type=True)

    Koishi.commands.unextend(AUTO_REACT_ROLE_COMMANDS)

    async with ScarletExecutor(limit=20) as executor:
        for gui in AUTO_REACT_ROLE_GUIS.values():
            await executor.add(gui.cancel())

    AUTO_REACT_ROLE_GUIS.clear()


AUTO_REACT_ROLE_COMMANDS = eventlist()

AUTO_REACT_ROLE_COLOR = Color.from_rgb(219, 31, 87)

BEHAVIOUR_FLAG_KEYS = {
    'remove_emoji_if_role': 0,
    'remove_role_if_emoji': 1,
}


class BehaviourFlag(int):
    @property
    def remove_emoji_if_role(self):
        return self & 1

    @property
Exemplo n.º 8
0
from hata import eventlist, Color, KOKORO, Embed, ScarletLock, sleep, Guild
from hata.ext.commands import Command, checks
from bot_utils.interpreter import parse_code_content
from bot_utils.shared import DUNGEON, KOISHI_PATH

# installing nsjail:
# make a folder for it somewhere
# $ sudo apt install autoconf bison flex gcc g++ git libprotobuf-dev libtool make pkg-config protobuf-compiler
# $ sudo apt-get install libnl-route-3-dev
# $ git clone https://github.com/google/nsjail.git
# $ cd nsjail && git checkout 3.0 # <- verison number
# $ make
# $ sudo cp ".../nsjail/nsjail" "/usr/sbin/" # Copy it.

SNEKBOX_COLOR = Color.from_rgb(255, 16, 124)
SNEKBOX_COMMANDS = eventlist(type_=Command, category='SNEKBOX')

CGROUP_PIDS_PARENT = Path('/sys/fs/cgroup/pids/NSJAIL')
CGROUP_MEMORY_PARENT = Path('/sys/fs/cgroup/memory/NSJAIL')

MEM_MAX = 52428800
MAX_TIMEOUT = 13

NSJAIL_EXECUTABLE = os.getenv('NSJAIL_PATH', '/usr/sbin/nsjail')
NSJAIL_CONFIG = os.getenv(
    'NSJAIL_CFG', os.path.join(KOISHI_PATH, 'bots', 'modules', 'nsjail.cfg'))

PYTHON_EXECUTABLE = '/usr/bin/python3.8'
SNEKBOXING_PATH = Path('/snekbox')

IS_UNIX = (sys.platform != 'win32')
Exemplo n.º 9
0
# -*- coding: utf-8 -*-
import re
from collections import deque

from hata import Embed, ERROR_CODES, eventlist, Color, BUILTIN_EMOJIS, Task, DiscordException, KOKORO
from hata.ext.commands import Timeouter, Cooldown, Command, GUI_STATE_READY, GUI_STATE_SWITCHING_PAGE, \
    GUI_STATE_CANCELLING, GUI_STATE_CANCELLED, GUI_STATE_SWITCHING_CTX, checks

from bot_utils.tools import BeautifulSoup, choose, pop_one, CooldownHandler, choose_notsame

BOORU_COLOR = Color.from_html('#138a50')
BOORU_COMMANDS = eventlist(type_=Command)


def setup(lib):
    Koishi.commands.extend(BOORU_COMMANDS)


def teardown(lib):
    Koishi.commands.unextend(BOORU_COMMANDS)


SAFE_BOORU = 'http://safebooru.org/index.php?page=dapi&s=post&q=index&tags='
NSFW_BOORU = 'http://gelbooru.com/index.php?page=dapi&s=post&q=index&tags='


class cached_booru_command(object):
    _FILTER = (
        'solo+-underwear+-sideboob+-pov_feet+-underboob+-upskirt+-sexually_suggestive+-ass+-bikini+-6%2Bgirls+-comic'
        '+-greyscale+')
Exemplo n.º 10
0
from hata import Color, Embed, eventlist, WaitTillExc, ReuBytesIO, Client, sleep, DiscordException, Emoji, now_as_id, \
    elapsed_time, ActivityUnknown, Status, ActivityTypes, BUILTIN_EMOJIS, ChannelText, ChannelCategory, id_to_time, \
    cchunkify, Permission, ICON_TYPE_NONE, KOKORO, Future, ERROR_CODES, ChannelVoice, ChannelStore, ChannelThread, \
    DATETIME_FORMAT_CODE

from hata.discord.utils import DISCORD_EPOCH_START
from hata.ext.commands import Command, Cooldown, Converter, ConverterFlag, checks, Pagination, Closer
from hata.ext.prettyprint import pchunkify

from PIL import Image as PIL

from bot_utils.tools import CooldownHandler, PAGINATION_5PN

UTILITY_COLOR = Color(0x5dc66f)
UTILITY_COMMANDS = eventlist(type_=Command)


def setup(lib):
    Koishi.commands.extend(UTILITY_COMMANDS)


def teardown(lib):
    Koishi.commands.unextend(UTILITY_COMMANDS)


@UTILITY_COMMANDS.from_class
class ping:
    async def command(client, message):
        await client.message_create(
            message.channel,
Exemplo n.º 11
0
from hata.discord.reader import EMPTY_VOICE_FRAME_ENCODED, EMPTY_VOICE_FRAME_DECODED
from hata.discord.player import AudioSource
from hata.discord.opus import OpusDecoder
from hata.ext.commands import Command, checks, Pagination, FlaggedAnnotation, ConverterFlag

from config import AUDIO_PATH, AUDIO_PLAY_POSSIBLE, MARISA_MODE

from bot_utils.shared import DUNGEON, WrapMultyple

if not MARISA_MODE:
    from bots.flan import FLAN_HELP_COLOR, CHESUTO_FOLDER, get_bgm, FLAN_HELP_COLOR

VOICE_COLORS = {}

if MARISA_MODE:
    VOICE_COMMANDS_MARISA = eventlist(category='VOICE', checks=[checks.guild_only()])
    WRAPPER = WrapMultyple(VOICE_COMMANDS_MARISA)
    VOICE_COMMANDS_MAIN = VOICE_COMMANDS_MARISA
    VOICE_COMMANDS_CHESUTO = WrapMultyple()
    
    MAIN_VOICE_COLOR = Color.from_rgb(121, 231, 78)
    VOICE_COLORS[Marisa] = MAIN_VOICE_COLOR
else:
    VOICE_COMMANDS_KOISHI = eventlist(category='VOICE', checks=[checks.guild_only()])
    VOICE_COMMANDS_FLAN = eventlist(checks=[checks.guild_only()])
    WRAPPER = WrapMultyple(VOICE_COMMANDS_KOISHI, VOICE_COMMANDS_FLAN)
    VOICE_COMMANDS_MAIN = VOICE_COMMANDS_KOISHI
    VOICE_COMMANDS_CHESUTO = VOICE_COMMANDS_FLAN
    
    MAIN_VOICE_COLOR = Color.from_rgb(235, 52, 207)
    VOICE_COLORS[Flan] = FLAN_HELP_COLOR
Exemplo n.º 12
0
from config import AUDIO_PATH, AUDIO_PLAY_POSSIBLE, MARISA_MODE

from bot_utils.shared import GUILD__NEKO_DUNGEON
from hata.ext.commands_v2 import checks

if not MARISA_MODE:
    from bots.flan import COLOR__FLAN_HELP, CHESUTO_FOLDER, get_bgm, get_random_bgm

VOICE_COLORS = {}

SLASH_CLIENT: [type(None), Client]

if MARISA_MODE:
    Marisa: Client
    VOICE_COMMANDS_MARISA = eventlist(category='VOICE', )
    VOICE_COMMAND_CLIENT = Marisa

    MAIN_VOICE_COLOR = Color.from_rgb(121, 231, 78)
    VOICE_COLORS[Marisa] = MAIN_VOICE_COLOR
else:
    Flan: Client
    Koishi: Client
    VOICE_COMMANDS_FLAN = eventlist(checks=checks.guild_only())
    VOICE_COMMAND_CLIENT = Flan

    MAIN_VOICE_COLOR = Color.from_rgb(235, 52, 207)
    VOICE_COLORS[Flan] = COLOR__FLAN_HELP
    VOICE_COLORS[Koishi] = MAIN_VOICE_COLOR

if AUDIO_PATH is not None:
Exemplo n.º 13
0
    from PIL.BmpImagePlugin import BmpImageFile as image_type_BMP
    from PIL.JpegImagePlugin import JpegImageFile as image_type_JPG
    UPLOAD = True
except ImportError:
    UPLOAD = False

UPLOAD_LOCK = Lock(KOKORO)

from bot_utils.tools import choose
from bot_utils.shared import KOISHI_PATH

splitext = os.path.splitext
join = os.path.join

IMAGE_COLOR = Color(0x5dc66f)
IMAGE_COMMANDS = eventlist(type_=Command)


def setup(lib):
    load_images()
    Koishi.commands.extend(IMAGE_COMMANDS)


def teardown(lib):
    Koishi.commands.unextend(IMAGE_COMMANDS)


IMAGES_STATIC = []
IMAGES_ANIMATED = []
IMAGES_ALL = []
Exemplo n.º 14
0
from hata import eventlist, Embed
from hata.events_compiler import ContentParser

extension = eventlist()


@extension
async def pat(self, message, content):
    await self.message_create(
        message.channel,
        embed=Embed(description=f"{self:m} pats {message.author:m}"))


@extension
@ContentParser("user, flags=mna, default='message.author'")
async def rate(client, message, target):
    if client is target:
        rating = 10
    else:
        rating = target.id % 11

    await client.message_create(
        message.channel,
        embed=Embed(description=f"I rate {target:m} {rating}/10."))
Exemplo n.º 15
0
# -*- coding: utf-8 -*-
from hata import Task, Client, User, CHANNELS, Embed, eventlist, Color, WebhookType

from hata.ext.commands import checks, Command

CHANNELLER_COMMANDS = eventlist(type_=Command)
CHANNELLER_COLOR = Color.from_rgb(129, 158, 0)


def setup(lib):
    Koishi.commands.extend(CHANNELLER_COMMANDS)


def teardown(lib):
    Koishi.commands.unextend(CHANNELLER_COMMANDS)


class Channeller_v_del(object):
    __slots__ = ('parent', )

    def __init__(self, parent):
        self.parent = parent

    async def __call__(self, client, message):
        if not isinstance(message.author, (Client, User)):
            return

        source_channel = message.channel
        user = message.author

        content = message.clean_content
Exemplo n.º 16
0
# -*- coding: utf-8 -*-
from hata import Color, Embed, eventlist, parse_oauth2_redirect_url, sleep, DiscordException, ERROR_CODES, \
    cr_pg_channel_object, ChannelText, cchunkify, imultidict
from hata.ext.commands import Command, checks, Pagination
from hata.ext.prettyprint import pchunkify

OAUTH2_COLOR = Color.from_rgb(148, 0, 211)
OAUTH2_COMMANDS = eventlist(type_=Command, category='OAUTH2')


def setup(lib):
    Koishi.command_processer.create_category('OAUTH2',
                                             checks=[checks.owner_only()])
    Koishi.commands.extend(OAUTH2_COMMANDS)


def teardown(lib):
    Koishi.command_processer.delete_category('OAUTH2')


VALUABLE_SCOPES = [
    'identify',
    'connections',
    'guilds',
    'guilds.join',
    'email',
    'applications.builds.read',
    'applications.builds.upload',
    'applications.entitlements',
    'applications.store.update',
]
Exemplo n.º 17
0
from hata.discord.http import URLS
from hata.backend.hdrs import AUTHORIZATION
from hata.ext.commands import Command, ChooseMenu, checks, Pagination, Converter, ConverterFlag, Closer, \
    FlaggedAnnotation
from hata.discord.utils import Discord_hdrs
from hata.discord.http import API_ENDPOINT, CONTENT_TYPE
from hata.discord.parsers import PARSERS
from hata.ext.prettyprint import pchunkify
from hata.discord.emoji import create_partial_emoji
from hata.ext.patchouli import map_module, MAPPED_OBJECTS

from bot_utils.shared import KOISHI_PATH

TEST_COMMANDS = eventlist(
    type_=Command,
    category='TEST COMMANDS',
)

map_module('hata')


def setup(lib):
    main_client.commands.extend(TEST_COMMANDS)


def teardown(lib):
    main_client.commands.unextend(TEST_COMMANDS)


@TEST_COMMANDS
async def test_choose_menu_repr(client, message):
Exemplo n.º 18
0
from hata import Color, Embed, eventlist, Permission, DiscordException, sleep, Message, Emoji, BUILTIN_EMOJIS, \
    ERROR_CODES, ChannelBase, User, AuditLogEvent, KOKORO
from hata.ext.commands import Command, Converter, checks, Pagination, ConverterFlag, wait_for_reaction
from hata.ext.prettyprint import pchunkify

from bot_utils.shared import KOISHI_PREFIX, permission_check_handler, not_guild_owner_handler, not_bot_owner_handler

ADMINISTRATION_COLOR = Color.from_rgb(148, 0, 211)
ADMINISTRATION_COMMANDS = eventlist(type_=Command)

def setup(lib):
    category = Koishi.command_processer.get_category('ADMINISTRATION')
    if (category is None):
        Koishi.command_processer.create_category('ADMINISTRATION',)
    
    Koishi.commands.extend(ADMINISTRATION_COMMANDS)

def teardown(lib):
    Koishi.commands.unextend(ADMINISTRATION_COMMANDS)

@ADMINISTRATION_COMMANDS.from_class
class clear:
    async def command(client, message, limit : Converter('int', default=1,), reason):
        if not reason:
            reason = f'{message.author.full_name} asked for it'
        if limit>0:
            await client.message_delete_sequence(channel=message.channel,limit=limit,reason=reason)
    
    category = 'ADMINISTRATION'
    #checks = [checks.has_permissions(Permission().update_by_keys(manage_messages=True), handler=permission_check_handler)]
    checks = [checks.owner_only()]
Exemplo n.º 19
0
# -*- coding: utf-8 -*-
import os
from random import randint

from hata import ERROR_CODES, BUILTIN_EMOJIS, CancelledError, Task, sleep, InvalidStateError, any_to_any, Color, \
    Embed, DiscordException, ReuBytesIO, eventlist, LOOP_TIME

from hata.ext.commands import GUI_STATE_READY, GUI_STATE_SWITCHING_PAGE, GUI_STATE_CANCELLING, GUI_STATE_CANCELLED, \
    GUI_STATE_SWITCHING_CTX, Timeouter, Command, checks

from bot_utils.shared import KOISHI_PATH
from PIL import Image as PIL

KANAKO_COMMANDS = eventlist(type_=Command)


def setup(lib):
    Koishi.commands.extend(KANAKO_COMMANDS)


def teardown(lib):
    Koishi.commands.unextend(KANAKO_COMMANDS)


FONT = PIL.font(os.path.join(KOISHI_PATH, 'library', 'Kozuka.otf'), 90)
FONT_COLOR = (162, 61, 229)

del os


def draw(buffer, text):