Beispiel #1
0
    def __init__(self, locals_):
        self.lock = Lock(KOKORO)

        printer = InterpreterPrinter()
        locals_['print'] = printer
        self.printer = printer

        inputter = InterpreterInputter(self)
        locals_['input'] = inputter
        self.inputter = inputter

        self.locals = locals_
Beispiel #2
0
    def __init__(self, locals_):

        for variable_name in {
                '__name__', '__package__', '__loader__', '__spec__',
                '__builtins__', '__file__'
        }:
            locals_[variable_name] = getattr(hata, variable_name)

        for variable_name in hata.__all__:
            locals_[variable_name] = getattr(hata, variable_name)

        self.lock = Lock(KOKORO)
        self.locals = locals_
Beispiel #3
0
class Interpreter:
    __slots__ = ('locals', 'lock')

    def __init__(self, locals_):

        for variable_name in {
                '__name__', '__package__', '__loader__', '__spec__',
                '__builtins__', '__file__'
        }:
            locals_[variable_name] = getattr(hata, variable_name)

        for variable_name in hata.__all__:
            locals_[variable_name] = getattr(hata, variable_name)

        self.lock = Lock(KOKORO)
        self.locals = locals_

    async def __call__(self, client, message, content):
        if not client.is_owner(message.author):
            await client.message_create(message.channel,
                                        'You are not my boss!')
            return

        if self.lock.locked():
            await client.message_create(message.channel,
                                        'An execution is already running.')
            return

        async with self.lock:
            result, is_exception = parse_code_content(content,
                                                      'No code to execute.')
            if is_exception:
                await client.message_create(message.channel,
                                            embed=Embed(
                                                'Parsing error', result))
                return

            with StringIO() as buffer:
                try:
                    code_object = compile(result,
                                          'online_interpreter',
                                          'exec',
                                          flags=COMPILE_FLAGS)
                except SyntaxError as err:
                    buffer.write(
                        f'{err.__class__.__name__} at line {err.lineno}: {err.msg}\n'
                        f'{result[err.lineno-1]}\n'
                        f'{" "*(err.offset-1)}^')

                else:
                    locals_ = self.locals
                    locals_['print'] = partial_func(raw_print, buffer)
                    locals_['input'] = partial_func(raw_input)

                    try:
                        function = FunctionType(code_object, locals_)
                        coroutine = function()
                        if is_awaitable(coroutine):
                            await coroutine
                    except BaseException as err:
                        await KOKORO.render_exc_async(err, file=buffer)

                page_contents = get_buffer_value(buffer)

            pages = []

            if (page_contents is not None) and page_contents:
                amount = len(page_contents)
                for index, page_content in enumerate(page_contents, 1):
                    pages.append(
                        Embed(
                            'Output:',
                            page_content).add_footer(f'page {index}/{amount}'))

            else:
                pages.append(Embed('No output'))

        await Pagination(client, message.channel, pages, timeout=240.)
Beispiel #4
0
from hata import Client, Message, Embed
import json
from hata.ext.commands import setup_ext_commands
from character import *
from hata import KOKORO, Lock, enter_executor

import cattr

FILE_LOCK = Lock(KOKORO)

secrets = json.load(open('secrets.json'))
Faito = Client(secrets['token'])
setup_ext_commands(Faito, '!')
# dictionary pointing user.id -> character
characters = {}
# list of battles
battles = []
battle_locks = []
characters_lock = Lock(KOKORO)


@Faito.events
async def ready(client):
    print(f'{client:f} logged in.')


@Faito.commands
async def ping(client, message):
    await client.message_create(message.channel, 'pong')

Beispiel #5
0
 def __init__(self, api_key):
     self.api_key = api_key
     self.reset_at = 0.0
     self.rate_limited = False
     self.lock = Lock(KOKORO)
Beispiel #6
0
from hata import is_mention, ReuAsyncIO, AsyncIO, Embed, Color, KOKORO, Lock, Client, parse_message_reference, \
    MESSAGES, DiscordException, ERROR_CODES, CHANNELS, Attachment, sanitize_mentions
from hata.ext.slash import InteractionResponse, abort

try:
    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):
Beispiel #7
0
    def __init__(self, partner):
        self.partner = partner

    def __call__(self, message):
        if message.author == self.partner:
            return True

        return False


INITIAL_MESSAGE = 'message_initial'
REQUEST_APPROVED = 'message_approved'
RECEIVED = 'message_received'
SYNC_DONE = 'message_done'

SYNC_LOCK = Lock(KOKORO)


def get_modified_files(days_allowed):
    days_allowed = timedelta(days=days_allowed)
    should_send = []

    min_time = datetime.now() - days_allowed
    for file in flatten_paths():
        if file.modified > min_time:
            should_send.append(file)

    return should_send


async def send_file(client, file):
Beispiel #8
0
from datetime import datetime
from difflib import get_close_matches

from bot_utils.shared import CATEGORY__NEKO_DUNGEON__BOTS, PATH__KOISHI, ROLE__NEKO_DUNGEON__MODERATOR
from bot_utils.tools import Cell

from hata import Lock, KOKORO, alchemy_incendiary, Task, Embed, DiscordException, ERROR_CODES, Client, \
    BUILTIN_EMOJIS
from hata.ext.slash import Button, Row, wait_for_component_interaction
from hata.ext.slash.menus import Pagination, Closer
from hata.ext.commands_v2 import checks

FILE_NAME = 'channel_names.csv'

FILE_PATH = os.path.join(PATH__KOISHI, 'bots', 'modules', FILE_NAME)
FILE_LOCK = Lock(KOKORO)
EDIT_LOCK = Lock(KOKORO)

DEFAULT_NAME = 'go-go-maniac'

DAY = 24.0 * 60.0 * 60.0
DAY_CHANCE_MULTIPLIER = 0.01 / DAY

SPACE_CHAR = '-'

CHANNEL_CHAR_TABLE = {}
for source, target in (
    ('!', 'ǃ'),
    ('?', '?'),
):
    CHANNEL_CHAR_TABLE[source] = target
Beispiel #9
0
class Interpreter(object):
    __slots__ = (
        'inputter',
        'locals',
        'lock',
        'printer',
    )

    def __init__(self, locals_):
        self.lock = Lock(KOKORO)

        printer = InterpreterPrinter()
        locals_['print'] = printer
        self.printer = printer

        inputter = InterpreterInputter(self)
        locals_['input'] = inputter
        self.inputter = inputter

        self.locals = locals_

    async def __call__(self, client, message, content):
        if not client.is_owner(message.author):
            await client.message_create(message.channel,
                                        'You are not my boss!')
            return

        if self.lock.locked():
            await client.message_create(message.channel,
                                        'An execution is already running.')
            return

        self.inputter.set(client, message.channel)

        async with self.lock:
            result, is_exception = parse_code_content(content,
                                                      'No code to execute.')
            if is_exception:
                await client.message_create(message.channel,
                                            embed=Embed(
                                                'Parsing error', result))
                return

            printer = self.printer

            try:
                code_object = compile(result, 'online_interpreter', 'exec')
            except SyntaxError as err:
                printer.write(
                    f'{err.__class__.__name__} at line {err.lineno}: {err.msg}\n{result[err.lineno-1]}\n{" "*(err.offset-1)}^'
                )
            else:
                try:
                    await client.loop.run_in_executor(
                        alchemy_incendiary(
                            exec,
                            (code_object, self.locals),
                        ), )
                except BaseException as err:
                    await client.loop.render_exc_async(err, file=printer)

            if printer:
                pages = []
                while printer:
                    pages.append(Embed('Output:', printer.get_value()))

                amount = len(pages)
                for index, embed in enumerate(pages, 1):
                    embed.add_footer(f'page {index}/{amount}')

            else:
                pages = [Embed('No output')]
            await Pagination(client, message.channel, pages, 240.)
Beispiel #10
0
from html import unescape as html_unescape
from functools import partial as partial_func

from hata import Client, Embed, BUILTIN_EMOJIS, Lock, KOKORO, DiscordException, ERROR_CODES, WebhookType, Emoji
from hata.ext.command_utils import wait_for_reaction
from hata.ext.slash import abort

from bot_utils.tools import Cell
from bot_utils.shared import GUILD__NEKO_DUNGEON

SLASH_CLIENT: Client

LAST_MEME_AFTER = Cell()
MEME_QUEUE = []
MEME_URL = 'https://www.reddit.com/r/goodanimemes.json'
MEME_REQUEST_LOCK = Lock(KOKORO)


async def get_memes():
    if MEME_REQUEST_LOCK.locked():
        await MEME_REQUEST_LOCK
        return

    async with MEME_REQUEST_LOCK:
        after = LAST_MEME_AFTER.value
        if after is None:
            after = ''

        async with SLASH_CLIENT.http.get(MEME_URL,
                                         params={
                                             'limit': 100,
Beispiel #11
0
 def __init__(self):
     self.rate_limit_reset_at = 0.0
     self.lock = Lock(KOKORO)
Beispiel #12
0
from hata.ext.slash import abort

from sqlalchemy.sql import select, update

from bot_utils.shared import GUILD__NEKO_DUNGEON, PATH__KOISHI, EMOJI__HEART_CURRENCY
from bot_utils.models import DB_ENGINE, currency_model, CURRENCY_TABLE, item_model, ITEM_TABLE

SLASH_CLIENT: Client

ITEMS = {}

MARKET_COST_FEE = 0.15
MARKET_COST_RESET = 0.05
MARKET_COST_MIN = 40

COST_FILE_LOCK = Lock(KOKORO)
COST_FILE_PATH = os.path.join(PATH__KOISHI, 'library', 'witch_craft_costs.json')

class CookingFactor:
    __slots__ = ('flavor', 'fruit', 'meat', 'monster', 'mushroom', 'vegetable')
    def __new__(cls, *, flavor=0, fruit=0, meat=0, monster=0, mushroom=0, vegetable=0):
        self = object.__new__(cls)
        
        self.flavor = flavor
        self.fruit = fruit
        self.meat = meat
        self.monster = monster
        self.vegetable = vegetable
        self.mushroom = mushroom
        
        return self