async def init(bot): chat=bot.message.channel user=str(bot.message.author.name) try: #await logger.print_to_file(str(type(bot.message.author))) if bot.message.channel.is_private: await botfunc.autoDelete(10, await bot.sendMessage( "This is a private chat."),bot.message) return False if await config.getConf(bot.message.server.id, "music_bot") == False: await botfunc.autoDelete(10, await bot.sendMessage( "Music bots are disabled on this server."),bot.message) return False if bot.message.author.voice_channel is None: await botfunc.autoDelete(10, await bot.sendMessage( "You have to be in a voice channel."),bot.message) return False if bot.message.attachments is not None and len(bot.message.attachments)==1: if bot.message.attachments[0] is not None: bot.args = [] bot.args.append(bot.message.attachments[0]['url']) if not bot.args[0].endswith(".mp3") and not bot.args[0].endswith(".wav"): await botfunc.autoDelete(10, await bot.sendMessage( "The attachment has to be an MP3 file!"),bot.message) return False if len(bot.args)==0: await botfunc.autoDelete(10, await bot.sendMessage( "You have to enter a link or attach a file."),bot.message) return False server_id = bot.message.server.id if not server_id in global_vars.music_bots or not await global_vars.music_bots[server_id].is_playing(): await botfunc.autoDelete(10,bot.message) # Auto-Delete if not server_id in global_vars.music_bots or not await global_vars.music_bots.get(server_id).is_connected(): global_vars.music_bots[server_id] = MusicPlayer(bot) try: await global_vars.music_bots[server_id].connect() except: await global_vars.music_bots[server_id].disconnect() return False logger.PrintException(bot.message) if "http://" in bot.args or "https://" in bot.args: url = "%20".join(bot.args) else: url = " ".join(bot.args) await global_vars.music_bots[server_id].play(Music(bot.message.author, "ytdl", url)) else: try: func = importlib.import_module('commands.queue') importlib.reload(func) await func.init(bot) except Exception as e: if "No module named" in str(e): return False logger.PrintException(bot.message) return except: logger.PrintException(bot.message)
def __init__(self, map_file): self.music = Music() self.map_file = pytmx.load_pygame(map_file) # IDEA: is needed. Player here or in main class? self.player = Player() self.background_tiles = pygame.sprite.Group() self.collision_tiles = pygame.sprite.Group() self.items = pygame.sprite.Group() self.items.add(Item(3, 32, 32)) self.items.add(Item(1, 300, 320)) self.items.add(Item(0, 64, 64)) self.items.add(Item(0, 400, 400)) # Load tiles for x, y, image in self.map_file.layers[0].tiles(): self.background_tiles.add(Tile(x*self.map_file.tilewidth, y*self.map_file.tileheight, image)) for x, y, image in self.map_file.layers[1].tiles(): self.collision_tiles.add(Tile(x*self.map_file.tilewidth, y*self.map_file.tileheight, image))
async def init(bot): chat = bot.message.channel user = str(bot.message.author.name) try: server_id = bot.message.server.id if server_id in global_vars.music_bots and await global_vars.music_bots.get( server_id).is_connected(): if global_vars.music_bots[server_id].shutting_down == False: if bot.message.attachments is not None and len( bot.message.attachments) == 1: if bot.message.attachments[0] is not None: bot.args = [] bot.args.append(bot.message.attachments[0]['url']) if not bot.args[0].endswith( ".mp3" ) and not not bot.args[0].endswith(".wav"): await botfunc.autoDelete( 10, await bot.sendMessage( "The attachment has to be an MP3 file!"), bot.message) return False done = False if len(bot.args) == 0 or (len(bot.args[0]) == 1 and (isinstance(bot.args[0], int) or bot.args[0].isdigit())): page = 1 queue = await global_vars.music_bots[server_id].queuelist() pages = math.ceil(len(queue) / 10) if len(bot.args) == 1: page = int(bot.args[0]) if page > pages: page = pages response = "" start = ((page - 1) * 10) end = start + 9 if pages > 1: response = "--> **Page {}** / {}\r\n".format( page, pages) for id, entry in enumerate(queue): if id >= start and id <= end: val = re.search('<@!?(.*)>', entry.user) if val: user = await search.user(chat, val.group(1)) user = user.display_name else: user = entry.user response += "{}. `{}` by `{}`\r\n".format( id + 1, entry.title, user) if len(response) == 0: response = "The queue is empty" #await botfunc.autoDelete(20,await bot.sendMessage(response),bot.message) await botfunc.autoDelete(20, await bot.sendMessage(response), bot.message) return if "http://" in bot.args or "https://" in bot.args: url = "%20".join(bot.args) else: url = " ".join(bot.args) if not "http://" in url and not "https://" in url: url = await ytsearch(" ".join(bot.args)) if url is None: await botfunc.autoDelete( 10, await bot.sendMessage("Nothing found for `{}`.".format( " ".join(bot.args))), bot.message) return False title = await get_title(url) if title is None: await botfunc.autoDelete( 10, await bot.sendMessage( "Could not play {}. This video is banned in my country." .format(url)), bot.message) return False done = await global_vars.music_bots[server_id].add( Music(bot.message.author, "ytdl", url, title)) if done != False: if await global_vars.music_bots[server_id].is_playing(): await botfunc.autoDelete( 10, await bot.sendMessage( "`{}`\r\nAdded to queue. You are queued in place {} ." .format(title, done)), bot.message) else: await botfunc.autoDelete(10, bot.message) await global_vars.music_bots[server_id].playNext() return True else: await botfunc.autoDelete( 10, await bot.sendMessage( "The queue is full. Please try again later."), bot.message) return False else: await botfunc.autoDelete( 10, await bot.sendMessage( "The current player is done and about to shut down. Please start a new one once it's disconnected." ), bot.message) #del global_vars.music_bots[server_id] return False try: func = importlib.import_module('commands.play') importlib.reload(func) await func.init(bot) except Exception as e: if "No module named" in str(e): return False logger.PrintException(bot) return except: logger.PrintException(bot.message)
import re from functools import wraps from flask import request, jsonify, g from flask_login import login_required from flask_helper import RenderTemplate, support_upload2 from zh_config import db_conf_path, upload_folder, file_prefix_url from classes.music import Music from web01 import create_blue __author__ = 'meisa' url_prefix = "/music" rt = RenderTemplate("music") music_view = create_blue("music", url_prefix=url_prefix, menu_list={"title": u"音乐管理"}, auth_required=False) c_music = Music(db_conf_path) def refer_music_no(f): @wraps(f) def decorated_function(*args, **kwargs): if "Referer" not in request.headers: g.ref_url = "" else: g.ref_url = request.headers["Referer"] find_no = re.findall("music_no=(\\d+)", g.ref_url) if len(find_no) > 0: g.music_no = find_no[0] elif "music_no" in request.args: g.music_no = request.args["music_no"] else:
def getMusic(self): song = self.getHeaders() dictionnary = self.getVoice() music = Music(song, dictionnary) return music
def update(self): # Handle collision with items for item in self.items: if item.rect.colliderect(self.player.rect): if isinstance(item, Coin): Music.coin_pick() self.player.inventory.gold += item.value self.items.remove(item) else: if self.player.inventory.add(item): Music.item_pick() self.items.remove(item) # Handle collision with tiles before # TODO: Check if it really works, cuz I don't believe if self.player.vector["x"]: player_rect = self.player.rect.copy() player_rect.x += self.player.vector["x"] collision_flag = False for tile in self.collision_tiles: if player_rect.colliderect(tile.rect): if self.player.vector["x"] > 0: player_rect.right = tile.rect.left else: player_rect.left = tile.rect.right collision_flag = True if collision_flag: Cam.x -= player_rect.x - self.player.rect.x self.player.x += player_rect.x - self.player.rect.x else: Cam.x -= self.player.vector["x"] self.player.x += self.player.vector["x"] self.player.vector["x"] = 0 if self.player.vector["y"]: player_rect = self.player.rect.copy() player_rect.y += self.player.vector["y"] collision_flag = False for tile in self.collision_tiles: if player_rect.colliderect(tile.rect): if self.player.vector["y"] > 0: player_rect.bottom = tile.rect.top else: player_rect.top = tile.rect.bottom collision_flag = True if collision_flag: Cam.y -= player_rect.y - self.player.rect.y self.player.y += player_rect.y - self.player.rect.y else: Cam.y -= self.player.vector["y"] self.player.y += self.player.vector["y"] self.player.vector["y"] = 0 self.player.update() self.player.inventory.update() self.background_tiles.update() self.collision_tiles.update() self.items.update()
def attack(self): if self.inventory.get_equipped_weapon(): self.attacking = True Music.player_attack()