async def join_match(user: Player, p: bytes) -> None: d = reader.handle_packet(p, (('id', osuTypes.i32), ('pw', osuTypes.string),)) _id = d['id'] pw = d['pw'] if _id >= 1000: if not (menu := glob.menus.get(_id)): # TODO: use pw instead of id return user.enqueue(writer.matchJoinFail()) ret = await menu.handle(user) # if we don't return a join failure also, its gonna think we are still in lobby if isinstance(ret, str): # return string message? user.enqueue( writer.sendMessage( fromname = glob.bot.name, msg = ret, tarname = user.name, fromid = glob.bot.id ) ) return user.enqueue(writer.matchJoinFail()) user.enqueue(writer.matchJoinFail()) return ret
async def d_req(user: Player, args: list) -> str: """Deny a map status request""" if len(args) < 1: return 'You must provide the request ID to deny!' request = await glob.db.fetchrow('SELECT * FROM requests WHERE id = %s', [int(args[0])]) _map = await Beatmap.bid_fetch(request['map']) ns = mapStatuses(request['status']) if (rq := await glob.players.get(name=request['requester'])): rq.enqueue( writer.sendMessage( fromname=glob.bot.name, msg= f'Your request to make {_map.embed} {ns.name.lower()} was denied by {user.name}!', tarname=rq.name, fromid=glob.bot.id))
def send(self, f: 'Player', msg: str, send_self: bool) -> None: if not send_self: self.enqueue(writer.sendMessage(f.name, msg, self.name, f.id), ignore=f.id) else: self.enqueue(writer.sendMessage(f.name, msg, self.name, f.id))
async def send_pm(user: Player, p: bytes) -> None: d = reader.handle_packet(p, (('msg', osuTypes.message),)) msg = d['msg'].msg tarname = d['msg'].tarname if not (target := await glob.players.get(name=tarname)): log(f'{user.name} tried to send message to offline user {tarname}', Ansi.LRED) return if target is glob.bot: if msg.startswith(glob.config.prefix) and (cmd := await commands.process(user, msg)): user.enqueue( writer.sendMessage( fromname = target.name, msg = cmd, tarname = user.name, fromid = target.id ) ) elif m := regexes.np_regex.match(msg): user.np = await Beatmap.bid_fetch(int(m['bid'])) np = await user.np.np_msg(user) user.enqueue( writer.sendMessage( fromname = target.name, msg = np, tarname = user.name, fromid = target.id )
clan_name = args[1] clan = glob.clans.get(await glob.db.fetchval( 'SELECT id FROM clans WHERE name = %s', [clan_name])) if not clan: return 'We could not find a clan by this name!' if not (owner := await glob.players.get(id=clan.owner)): return 'Clan owner offline, battle request cancelled!' if args[1] == 'deny': owner.enqueue( writer.sendMessage( fromname=glob.bot.name, msg= f'{user.name} denied your request to battle their clan {clan.name}!', tarname=owner.name, fromid=glob.bot.id)) return 'Battle request denied!' # battle was accepted, create the battle match # TODO: clan battle object to clean this shit up? user.enqueue( writer.sendMessage(fromname=glob.bot.name, msg='Request accepted! Creating match...', tarname=user.name, fromid=glob.bot.id)) owner.enqueue(