def setup(): # Configure & load HTTP Interface template_path = join(abspath(dirname(__file__)), 'templates') aiohttp_jinja2.setup(web_app, loader=jinja2.FileSystemLoader(template_path)) web_app.router.add_get("/{server_id}", handle_index) web_app.router.add_get("/{server_id}/play/{song_id}", handle_play) http_server = loop.create_server( web_app.make_handler(), config.get("http_host", "localhost"), config.get("http_port", 8080), ssl=None, backlog=128 ) loop.run_until_complete(asyncio.gather(http_server, web_app.startup(), loop=loop))
def music_playlist_url(server_id): global ext_ip try: if not ext_ip: ext_ip = ipgetter.myip() except Exception: ext_ip = "0.0.0.0" return "http://{}:{}/{}".format(ext_ip, config.get("http_port", 8080), server_id)
async def handle_index(request): server_id = request.match_info['server_id'] server_state = await state.servers.get_server(server_id) return { "entries": media.fetch_media_files(config.get("music_path")), "now_playing": None, "current_song_id": server_state.song_id, "server_id": server_id }
async def do_rank(self, task: TaskState) -> bool: if len(task.args): bnet = task.args[0].replace("#", "-") else: bnet = config.get("bnet_id") stats = await overwatch.get_player_stats(bnet) if stats: msg = "{}: SR:{} LVL:{} W/L: {}/{} K/D: {}/{}".format( bnet, stats['rank'], stats['level'], stats['wins'], stats['losses'], stats['elims'], stats['deaths']) else: msg = "Error retrieving stats" return await self.send_message(task, msg)
def find_command(txt: str): """ Find the matching enum value from the txt value passed in, leading command prefixes are discarded for the matching. :param txt: :return: :rtype: Commands """ if not txt: return None prefix = config.get("prefix", "!") if txt[0] == prefix: txt = txt[1:] for name, member in Commands.__members__.items(): if name == txt.lower(): return member return Commands.record
def gen_help(cls, cmd_name=None, help_sep=" :100: ") -> str: prefix = config.get("prefix", "!") if cmd_name: try: cmd_name = cmd_name.name except AttributeError: pass if not cmd_name.startswith("do_"): cmd_name = "do_{}".format(cmd_name) resp = [] for k, v in cls.__dict__.items(): if k.startswith("do_"): if cmd_name and k != cmd_name: continue try: resp.append("{}{}: {}".format(prefix, k[3:], v.__help__)) except AttributeError: pass if len(resp) > 1: return help_sep.join(resp) return resp[0]
def main(): from roboto import model, http, loop, disc, config, commands # Parse & load config file config.update(parse_config('bot', "config.ini")) # Connect & Init DB model.init_db(config) # Load IRC Bot irc_bot = IrcBot.from_config(config, loop=loop) irc_bot.run(forever=False) # HTTP Server for playlist http.setup() # Start background task queue processor asyncio.ensure_future(commands.dispatcher.task_consumer(), loop=loop) # Start discord client disc.dc.run(config.get("discord_token"))
def add_cmd_prefix(cmd): return "{}{}".format(config.get("cmd", "!"), cmd)