Пример #1
0
async def prefix(ctx, new=None):
    if new is None:
        await ctx.send("Current prefix: " + config.get_prefix())
    else:
        bot.command_prefix = commands.when_mentioned_or(new)
        config.change_prefix(new)
        await ctx.send("Changed prefix to " + config.get_prefix())
        await bot.change_presence(
            activity=discord.Activity(type=discord.ActivityType.listening, name=f"{config.get_prefix()}help"))
Пример #2
0
async def on_message(message):
    if message.author != client.user:
        tmp = await check_triggers(message)
        if message.channel.is_private == False or message.content.startswith("!help") or message.content.startswith("!list") :
            sender ="<@"+ message.author.id+">"
            tells = commands.get_tells(sender)
            for tell in tells:
                tmp = await client.send_message(message.channel,tell)
            if message.content.startswith(config.get_prefix()):
                command = get_command(message.content)
                if command == "grab":
                    async for log in client.logs_from(message.channel,limit=2):
                        if not log.content.startswith("!grab"):
                            commands.add_grab(log)
                            tmp = await client.send_message(message.channel,"Grab Successful")
                elif command == "list" and config.check_command(command):
                    tmp = await client.send_message(message.author,commands.list_places())
                    tmp2 = await client.send_message(message.channel,"I have PM'd you the list of places")
                else:
                    try:
                        args = message.content.split(' ',1)[1]
                    except:
                        args = ""
                    if config.check_command(command):
                        tmp = await client.send_message(message.channel,commands.get_response(message,command,args))
                    else:
                        tmp = await client.send_message(message.channel,commands.get_unsupported_msg(command))
Пример #3
0
async def on_message(message: discord.Message):
    if message.author.bot or message.author.id in config.get_global(
            "user_blacklist"):
        return

    if (isinstance(message.channel, discord.DMChannel)
            or isinstance(message.channel, discord.GroupChannel) or
            message.channel.permissions_for(message.guild.me).send_messages):
        prefix = config.get_prefix(message.guild)
        if message.content.startswith(prefix):
            if not initialised:
                await message.channel.send(
                    "I've only just woken up, give me a second please!")
                return
            command = message.content[len(prefix):].split(
                " ")[0].lower()  # just command text
            args = message.content[len(prefix) + len(command) + 1:]
            if Hook.exists("public!" +
                           command) and util.check_command_permissions(
                               message, "public"):
                await Hook.get("public!" + command)(message, args)
            elif Hook.exists("admin!" +
                             command) and util.check_command_permissions(
                                 message, "admin"):
                await Hook.get("admin!" + command)(message, args)
            elif Hook.exists("owner!" +
                             command) and util.check_command_permissions(
                                 message, "owner"):
                await Hook.get("owner!" + command)(message, args)
            else:
                await message.channel.send(
                    "I don't know that command, sorry! Use the `help` command for a list of commands."
                )
        else:
            if not initialised:
                return
            await Hook.get("on_message")(message)
            if discord.utils.find(lambda m: m.id == client.user.id,
                                  message.mentions) is not None:
                await Hook.get("on_mention")(message)
            if isinstance(message.channel, discord.abc.PrivateChannel):
                await Hook.get("on_message_private")(message)
Пример #4
0
class Server(object):
    # expires is one year.
    CACHEEXPIRES = 31536000
    CONFIG = {
        '/': {
            'tools.trailing_slash.on': False,
            'tools.staticdir.root': config.get_prefix(),
            'request.methods_with_bodies': ('POST', 'PUT'),
            'tools.nocache.on': True
        },
        '/css': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/css',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False
        },
        '/js': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/js',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False
        },
        '/libs': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/libs',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False
        },
        '/images': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/images',
            'tools.nocache.on': False
        },
        '/data/screenshots': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'data/screenshots',
            'tools.nocache.on': False
        },
    }

    def __init__(self, options):
        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.server.socket_host = options.host
        cherrypy.server.socket_port = options.port
        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        self.app = cherrypy.tree.mount(Root(model_instance, dev_env),
                                       config=self.CONFIG)

    def start(self):
        cherrypy.quickstart(self.app)

    def stop(self):
        cherrypy.engine.exit()
Пример #5
0
def href(url):
    # for error.html, url is absolute path
    f = os.path.join(get_prefix(), 'ui', url.lstrip("/"))
    mtime = os.path.getmtime(f)
    return "%s?cacheBust=%s" % (url, mtime)
Пример #6
0
import discord
from discord.ext import commands
import config
from api_utils import handle_jokes

command_prefix = commands.when_mentioned_or(config.get_prefix())
bot = commands.Bot(command_prefix=command_prefix)
bot.remove_command("help")

print("version: ", discord.__version__)

# TODO: add pin function


@bot.event
async def on_ready():
    await bot.change_presence(
        activity=discord.Activity(
            type=discord.ActivityType.listening,
            name=f"{config.get_prefix()}help"
        )
    )
    print("bot is ready")


@bot.event
async def on_member_join(member: discord.Member):
    if (def_role := discord.utils.get(member.guild.roles, name="randoms")) is not None:
        await member.add_roles(def_role)
    else:
        def_role = await member.guild.create_role(name="randoms", color=discord.Colour(0x488579), hoist=True)
Пример #7
0
class Server(object):
    # expires is one year.
    CACHEEXPIRES = 31536000
    CONFIG = {
        '/': {
            'tools.trailing_slash.on': False,
            'tools.staticdir.root': config.get_prefix(),
            'request.methods_with_bodies': ('POST', 'PUT'),
            'tools.nocache.on': True,
            'tools.sessions.on': True,
            'tools.sessions.name': 'kimchi',
            'tools.sessions.httponly': True,
            'tools.sessions.storage_type': 'file',
            'tools.sessions.storage_path': config.get_session_path(),
            'tools.kimchiauth.on': False
        },
        '/vms': {
            'tools.kimchiauth.on': True
        },
        '/templates': {
            'tools.kimchiauth.on': True
        },
        '/storagepools': {
            'tools.kimchiauth.on': True
        },
        '/tasks': {
            'tools.kimchiauth.on': True
        },
        '/css': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/css',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False
        },
        '/js': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/js',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False
        },
        '/libs': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/libs',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False,
        },
        '/images': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/images',
            'tools.nocache.on': False
        },
        '/data/screenshots': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'data/screenshots',
            'tools.nocache.on': False
        }
    }

    def __init__(self, options):
        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_session_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        cherrypy.server.socket_host = options.host
        cherrypy.server.socket_port = options.port

        # SSL Server
        try:
            if options.ssl_port and options.ssl_port > 0:
                self._init_ssl(options)
        except AttributeError, e:
            pass

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        self.app = cherrypy.tree.mount(Root(model_instance, dev_env),
                                       config=self.CONFIG)
        cherrypy.lib.sessions.init()
Пример #8
0
def href(url):
    # for error.html, url is absolute path
    f = os.path.join(get_prefix(),'ui', url.lstrip("/"))
    mtime = os.path.getmtime(f)
    return "%s?cacheBust=%s" % (url, mtime)