Esempio n. 1
0
    async def google(client, event, query: (str, 'query')):
        yield

        success, result_or_error_message = await search(query)
        if not success:
            yield result_or_error_message

        pages = []

        limit = len(result_or_error_message)
        if limit:
            index = 0

            while index < limit:
                result = result_or_error_message[index]
                index += 1

                page_embed = Embed(result.title, result.description, Color.random(), result.url). \
                    add_footer(f'Page {index}/{limit}', client.avatar_url)

                image_url = result.image_url
                if (image_url is not None):
                    page_embed.add_thumbnail(image_url)

                pages.append(page_embed)
        else:
            embed = Embed(query, '*no result*')
            pages.append(embed)

        await Pagination(client, event, pages)
Esempio n. 2
0
# -*- coding: utf-8 -*-
import re, time
from random import randint

from hata import Color, filter_content, is_user_mention, Future, FutureWM, future_or_timeout, sleep, Task, \
    DiscordException, BUILTIN_EMOJIS, Embed, KOKORO, ERROR_CODES
from hata.ext.commands import WaitAndContinue, Converter, ConverterFlag, checks, Closer

BS_COLOR = Color.from_rgb(71, 130, 255)

def setup(lib):
    Koishi.commands(battle_manager, name='bs', checks=[checks.guild_only()], category='GAMES')

def teardown(lib):
    Koishi.commands.remove(battle_manager, name='bs')

async def bs_description(client, message):
    prefix = client.command_processer.get_prefix_for(message)
    return Embed('bs', (
        'Requests a battleship game with the given user.\n'
        f'Usage: `{prefix}bs *user*`'
        ), color=BS_COLOR).add_footer(
            'Guild only!')


OCEAN = BUILTIN_EMOJIS['ocean'].as_emoji

LINE_X_LEAD = ''.join([
    BUILTIN_EMOJIS['black_large_square'].as_emoji,
    BUILTIN_EMOJIS['one'].as_emoji,
    BUILTIN_EMOJIS['two'].as_emoji,
Esempio n. 3
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

from bot_utils.tools import choose
from bot_utils.shared import PATH__KOISHI, GUILD__NEKO_DUNGEON

SLASH_CLIENT: Client
UPLOAD_LOCK = Lock(KOKORO)

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

IMAGE_COLOR = Color(0x5dc66f)

IMAGES = []

IMAGE_TAG_HASHES = {}
IMAGE_STATISTICS = {}

FIND_TAGS_RP = re.compile('\S+')


class ImageDetail(set):
    __slots__ = ('path', 'animated')

    @classmethod
    def create(cls, path):
        name, ext = splitext(path)
Esempio n. 4
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',
]
Esempio n. 5
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'
Esempio n. 6
0
    cchunkify, ICON_TYPE_NONE, KOKORO, ChannelVoice, ChannelStore, ChannelThread, DATETIME_FORMAT_CODE, parse_color, \
    parse_message_reference, MESSAGES, CHANNELS, ID_RP, StickerFormat, ZEROUSER, future_or_timeout, ChannelDirectory

from hata.ext.slash.menus import Pagination
from hata.ext.prettyprint import pchunkify
from hata.ext.slash import abort, InteractionResponse, set_permission, Button, Row, ButtonStyle, \
    wait_for_component_interaction

from PIL import Image as PIL
from dateutil.relativedelta import relativedelta

from bot_utils.tools import PAGINATION_5PN
from bot_utils.shared import ROLE__NEKO_DUNGEON__TESTER, GUILD__NEKO_DUNGEON, ROLE__NEKO_DUNGEON__MODERATOR, \
    ROLE__NEKO_DUNGEON__ADMIN

UTILITY_COLOR = Color(0x5dc66f)

SLASH_CLIENT: Client


@SLASH_CLIENT.interactions(is_global=True)
async def rawr(client, event):
    """Sends a message with everyone from my universe."""
    yield

    channel = event.channel
    tasks = []

    for client_ in channel.clients:
        if client_ is client:
            coroutine = client.interaction_response_message_create(
Esempio n. 7
0
#Emoji.precreate(604698116494590202,name='ax').as_emoji

# Letters
#Emoji.precreate(604698116129816586,name='ay').as_emoji
#Emoji.precreate(604698116675076106,name='az').as_emoji
#Emoji.precreate(604698116482007194,name='aA').as_emoji
#Emoji.precreate(604698116435738625,name='aB').as_emoji
#Emoji.precreate(604698116163371009,name='aC').as_emoji
#Emoji.precreate(604698116490264586,name='aD').as_emoji
#Emoji.precreate(604698116548984832,name='aE').as_emoji
#Emoji.precreate(604698116540596252,name='aF').as_emoji

# Edge
#Emoji.precreate(604698116658167808,name='aG').as_emoji

EMBED_COLOR = Color.from_rgb(73, 245, 73)
EMBED_NAME_LENGTH = 200
EMBED_DESCRIPTION_LENGTH = 1600


class Rarity(object):
    INSTANCES = [NotImplemented] * 8
    BY_NAME = {}

    __slots__ = ('index', 'name', 'special', 'outlook')

    def __init__(self, index, name, special):
        self.index = index
        self.name = name
        self.special = special
Esempio n. 8
0
from subprocess import TimeoutExpired
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')
Esempio n. 9
0
Token = os.environ.get('Token')
APPLICATION_ID = os.environ.get('APPLICATION_ID')
GUILD = Guild.precreate(os.environ.get('GUILD_ID'))

Pichu = Client(Token, application_id=APPLICATION_ID)
setup_ext_slash(Pichu)

# emotes
CAT_FISH = Emoji.precreate(os.environ.get('CAT_FISH'))
CAT_SAD = Emoji.precreate(os.environ.get('CAT_SAD'))
CAT_WAY = Emoji.precreate(os.environ.get('CAT_WAY'))
NEKOGIRL_KISS = Emoji.precreate(os.environ.get("NEKOGIRL_KISS"))
NEKOGIRL_PEEK = Emoji.precreate(os.environ.get('NEKOGIRL_PEEK'))

# colors
CAT_FACT_COLOR = Color.from_html('#F6D33C')
OwO_COLOR = Color.from_html('#FF69B4')
NEKOGIRL_COLOR = Color.from_html('#FFB6C1')
CAT_COLOR = Color.from_html('#000000')

# data
CAT_FACTS = [
        "A house cat’s genome is 95.6 percent tiger, and they share many behaviors with their jungle ancestors, says Layla Morgan Wilde, a cat behavior expert and the founder of Cat Wisdom 101. These behaviors include scent marking by scratching, prey play, prey stalking, pouncing, chinning, and urine marking.",
        "Cats are believed to be the only mammals who don’t taste sweetness.",
        "Cats are nearsighted, but their peripheral vision and night vision are much better than that of humans.",
        "Cats are supposed to have 18 toes (five toes on each front paw; four toes on each back paw).",
        "Cats can jump up to six times their length.",
        "Cats’ claws all curve downward, which means that they can’t climb down trees head-first. Instead, they have to back down the trunk.",
        "Cats’ collarbones don’t connect to their other bones, as these bones are buried in their shoulder muscles.",
        "Cats have 230 bones, while humans only have 206.",
        "Cats have an extra organ that allows them to taste scents on the air, which is why your cat stares at you with her mouth open from time to time.",
Esempio n. 10
0
from hata import Task, User, CHANNELS, Embed, Client, Color, WebhookType, KOKORO

from hata.ext.commands_v2 import checks

CHANNELLER_COLOR = Color.from_rgb(129, 158, 0)


class Channeller_v_del:
    __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

        source_content = message.content
        source_embeds = message.embds
        source_attachments = message.attachments
        if source_attachments is None:
            source_attachment_names = None
        else:
            source_attachment_names = [
                attachment.name for attachment in source_attachments
            ]
        source_tts = message.tts
Esempio n. 11
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
    def remove_role_if_emoji(self):
        return (self >> 1) & 1
Esempio n. 12
0
FONT_COLOR = (162, 61, 229)

del os


def draw(buffer, text):
    image = PIL.new('RGBA', FONT.getsize(text), (0, 0, 0, 0))
    image.draw().text((0, 0), text, fill=FONT_COLOR, font=FONT)
    image.save(buffer, 'png')
    buffer.seek(0)
    return buffer


ACTIVE_GAMES = {}
CIRCLE_TIME = 60.
KANAKO_COLOR = Color.from_tuple(FONT_COLOR)

SLASH_CLIENT: Client
KANAKO = SLASH_CLIENT.interactions(
    None,
    name='kanako',
    description='Start a hiragana or a katakana quiz!',
    is_global=True,
)


@KANAKO.interactions
async def create_(
    client,
    event,
    map_: ([('hiragana', 'hiragana'),
Esempio n. 13
0
from hata import Embed, ERROR_CODES, Color, BUILTIN_EMOJIS, Client
from hata.ext.command_utils import ChooseMenu, Pagination
from hata.backend.utils import from_json
from hata.ext.slash import InteractionResponse, abort, Button, Row
from hata.ext.slash.menus import Menu
from hata.discord.http import LIBRARY_USER_AGENT
from hata.backend.headers import USER_AGENT, CONTENT_TYPE

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

WORD_MATCH_RP = re.compile('[^a-zA-z0-9]+')

HEADERS = {USER_AGENT: LIBRARY_USER_AGENT}

BOORU_COLOR = Color.from_html('#138a50')

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='

TOUHOU_REQUIRED = {
    'solo',
}

TOUHOU_BANNED = {
    'underwear',
    'sideboob',
    'pov_feet',
    'underboob',
    'upskirt',
    'sexually_suggestive',
Esempio n. 14
0
# -*- coding: utf-8 -*-
import re, sys

from bs4 import BeautifulSoup

from hata import Color, Task, Embed, KOKORO, eventlist
from hata.ext.commands import ChooseMenu, Pagination, Command
from hata.discord.utils import from_json, chunkify
from hata.ext.patchouli import map_module, MAPPED_OBJECTS, QualPath, FolderedUnit, search_paths

from bot_utils.shared import SATORI_HELP_COLOR

WORDMATCH_RP = re.compile('[^a-zA-z0-9]+')
WIKI_COLOR = Color.from_rgb(48, 217, 255)

DOCS_COMMANDS = eventlist(type_=Command)


def setup(lib):
    Satori.commands.extend(DOCS_COMMANDS)


def teardown(lib):
    Satori.commands.unextend(DOCS_COMMANDS)


map_module('hata')


async def wiki_description(client, message):
    prefix = client.command_processer.get_prefix_for(message)
Esempio n. 15
0
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
    VOICE_COLORS[Koishi] = MAIN_VOICE_COLOR


def setup(lib):
    if MARISA_MODE:
Esempio n. 16
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:
Esempio n. 17
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 EventThread, KOKORO, ExecutorThread, Client, Embed, Color, elapsed_time, Future, sleep
from hata.ext.commands_v2 import checks

from bot_utils.models import DB_ENGINE

STAT_COLOR = Color.from_rgb(61, 255, 249)

COMMAND_CLIENT: Client
COMMAND_CLIENT.command_processor.create_category('STATS',
                                                 checks=checks.owner_only())


@COMMAND_CLIENT.commands.from_class
class threads:
    async def command(client, message):
        thread_count_by_type = {}
        thread_count = 0

        for thread in list_threads():
            thread_count += 1
            thread_type = thread.__class__
Esempio n. 18
0
# -*- coding: utf-8 -*-
import re, os
from itertools import cycle

from hata import Guild, Embed, Color, Role, sleep, ReuAsyncIO, BUILTIN_EMOJIS, AsyncIO, ChannelText, KOKORO
from hata.backend.utils import sortedlist
from hata.ext.commands import setup_ext_commands, Cooldown, Pagination, checks, wait_for_reaction
from hata.ext.commands.helps.subterranean import SubterraneanHelpCommand

from bot_utils.shared import FLAN_PREFIX, FLAN_HELP_COLOR
from bot_utils.tools import CooldownHandler, MessageDeleteWaitfor, MessageEditWaitfor
from bot_utils.chesuto import Rarity, CARDS_BY_NAME, Card, PROTECTED_FILE_NAMES, CHESUTO_FOLDER, EMBED_NAME_LENGTH, get_card

CHESUTO_GUILD = Guild.precreate(598706074115244042)
CHESUTO_COLOR = Color.from_rgb(73, 245, 73)
CARDS_ROLE = Role.precreate(598708907816517632)
CARD_HDR_RP = re.compile(
    ' *(?:\*\*)? *(.+?) *(?:\[((?:token)|(?:passive)|(?:basic))\])? *(?:\(([a-z]+)\)?)? *(?:\*\*)?',
    re.I)
VISITORS_ROLE = Role.precreate(669875992159977492)
CHESUTO_BGM_MESSAGES = set()
CHESUTO_BGM_CHANNEL = ChannelText.precreate(707892105749594202)
CHESUTO_BGM_TRACKS = {}
CHESUTO_BGM_TRACKS_SORTED = sortedlist()
BGM_SPLITPATTERN = re.compile('([^ _-]+)')
BGM_NAME_PATTERN = re.compile('[a-z0-9]+', re.I)
PERCENT_RP = re.compile('(\d*)[%]?')

BMG_NAMES_W_S = {
    'backstory',
    'est',
Esempio n. 19
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()]
Esempio n. 20
0
ROLE__NEKO_DUNGEON__EVENT_MANAGER = Role.precreate(798913709019103284)
ROLE__NEKO_DUNGEON__EVENT_WINNER = Role.precreate(771989284231053323)
ROLE__NEKO_DUNGEON__EVENT_PARTICIPANT = Role.precreate(801608590720106496)
ROLE__NEKO_DUNGEON__HEART_BOOST = Role.precreate(846320725580709908)
ROLE__NEKO_DUNGEON__ADMIN = Role.precreate(403581319139033090)
ROLE__NEKO_DUNGEON__EMOJI_MANAGER = Role.precreate(864748298116268053)


INVITE__NEKO_DUNGEON = Invite.precreate('3cH2r5d')

CATEGORY__NEKO_DUNGEON__BOTS = ChannelCategory.precreate(445191611727478795)
CATEGORY__NEKO_DUNGEON__BIG_BRO = ChannelCategory.precreate(829104265049538620)

EMOJI__HEART_CURRENCY = Emoji.precreate(603533301516599296, name='youkai_kokoro')

COLOR__SATORI_HELP = Color.from_rgb(118, 0, 161)
COLOR__KOISHI_HELP = Color.from_html('#ffd21e')
COLOR__FLAN_HELP = Color.from_rgb(230, 69, 0)
COLOR__MARISA_HELP = Color.from_html('#e547ed')
COLOR__EVENT = Color(2316923)

LINK__KOISHI_GIT = 'https://github.com/HuyaneMatsu/Koishi'
LINK__HATA_GIT = 'https://github.com/HuyaneMatsu/hata'
LINK__HATA_DOCS = 'https://www.astil.dev/project/hata/docs/hata'
LINK__PASTE = 'https://hastebin.com/'
LINK__HATA_SLASH = 'https://github.com/HuyaneMatsu/hata/blob/master/docs/topics/slash.md'

USER__DISBOARD = User.precreate(302050872383242240, is_bot=True)

DEFAULT_CATEGORY_NAME = 'Uncategorized'