async def unrestrict(self, reason: str, fr: "Player") -> None: await self.remove_priv(Privileges.Restricted) self.restricted = False if self.token: self.enqueue( writer.restartServer(0)) # force relog if they're online await glob.db.execute( "INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) VALUES " "(%s, %s, %s, %s, %s)", ["unrestrict", reason, self.id, fr.id, time.time()], ) if wh_url := glob.config.webhooks["anticheat"]: wh = Webhook(url=wh_url) embed = Embed(title=f"") embed.set_author( url=f"https://{glob.config.domain}/u/{self.id}", icon_url=f"https://a.{glob.config.domain}/{self.id}", name=self.name, ) embed.add_field( name="New unrestricted user", value= f"{self.name} has been unrestricted by {fr.name} for {reason}.", inline=True, ) wh.add_embed(embed) await wh.post()
async def unban(self, reason: str, fr: "Player") -> None: await self.remove_priv(Privileges.Banned) await glob.db.execute( "INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) " "VALUES (%s, %s, %s, %s, %s)", ["unban", reason, self.id, fr.id, time.time()], ) if wh_url := glob.config.webhooks["anticheat"]: wh = Webhook(url=wh_url) embed = Embed(title=f"") embed.set_author( url=f"https://{glob.config.domain}/u/{self.id}", icon_url=f"https://a.{glob.config.domain}/{self.id}", name=self.name, ) embed.add_field( name="New unbanned user", value= f"{self.name} has been unbanned by {fr.name} for {reason}.", inline=True, ) wh.add_embed(embed) await wh.post()
async def unrestrict(self, reason: str, fr: 'Player') -> None: await self.remove_priv(Privileges.Restricted) self.restricted = False if self.token: self.enqueue(writer.restartServer(0)) # force relog if they're online await glob.db.execute( 'INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) VALUES ' '(%s, %s, %s, %s, %s)', ['unrestrict', reason, self.id, fr.id, time.time()] ) if (wh_url := glob.config.webhooks['anticheat']): wh = Webhook(url=wh_url) embed = Embed(title=f'') embed.set_author( url=f'https://{glob.config.domain}/u/{self.id}', icon_url=f'https://a.{glob.config.domain}/{self.id}', name=self.name ) embed.add_field( name='New unrestricted user', value=f'{self.name} has been unrestricted by {fr.name} for {reason}.', inline=True ) wh.add_embed(embed) await wh.post()
async def unban(self, reason: str, fr: 'Player') -> None: await self.remove_priv(Privileges.Banned) await glob.db.execute( 'INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) ' 'VALUES (%s, %s, %s, %s, %s)', ['unban', reason, self.id, fr.id, time.time()] ) if (wh_url := glob.config.webhooks['anticheat']): wh = Webhook(url=wh_url) embed = Embed(title=f'') embed.set_author( url=f'https://{glob.config.domain}/u/{self.id}', icon_url=f'https://a.{glob.config.domain}/{self.id}', name=self.name ) embed.add_field( name='New unbanned user', value=f'{self.name} has been unbanned by {fr.name} for {reason}.', inline=True ) wh.add_embed(embed) await wh.post()
async def restrict(self, reason: str, fr: "Player") -> None: if self.restricted: return # ? await self.add_priv(Privileges.Restricted) self.restricted = True if self.token: self.enqueue( writer.restartServer(0)) # force relog if they're online await glob.db.execute( "INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) " "VALUES (%s, %s, %s, %s, %s)", ["restrict", reason, self.id, fr.id, time.time()], ) for mode, stat in self.stats.items(): mode_name = osuModes(mode).name await glob.redis.zrem(f"asahi:leaderboard:{mode_name}", self.id) await glob.redis.zrem( f"asahi:leaderboard:{mode_name}:{self.country_iso}", self.id, ) stat.rank = 0 stat.country_rank = 0 if wh_url := glob.config.webhooks["anticheat"]: wh = Webhook(url=wh_url) embed = Embed(title=f"") embed.set_author( url=f"https://{glob.config.domain}/u/{self.id}", icon_url=f"https://a.{glob.config.domain}/{self.id}", name=self.name, ) embed.add_field( name="New restricted user", value= f"{self.name} has been restricted by {fr.name} for {reason}.", inline=True, ) wh.add_embed(embed) await wh.post()
async def a_req(user: Player, args: list) -> str: """Accept a map status request""" if len(args) < 2: return "You must provide the request ID and status to set!" request = await glob.db.fetchrow( "SELECT * FROM requests WHERE id = %s", [int(args[0])], ) _map = await Beatmap.bid_fetch(request["map"]) ns = mapStatuses.from_str(args[1]) # TODO: better management for ranking only certain difficulties _set = await glob.db.fetch("SELECT md5 FROM maps WHERE sid = %s", [_map.sid]) for m in _set: bm = await Beatmap.from_md5(m["md5"]) bm.status = ns bm.frozen = True # reset lb cache in case of major status change bm.lb = None bm.lb_rx = None bm.lb_ap = None await bm.save() glob.cache["maps"][bm.md5] = bm if wh_url := glob.config.webhooks["maps"]: wh = Webhook(url=wh_url) embed = Embed(title="") embed.set_author( url=f"https://{glob.config.domain}/u/{user.id}", name=user.name, icon_url=f"https://a.{glob.config.domain}/{user.id}", ) embed.set_image( url=f"https://assets.ppy.sh/beatmaps/{_map.sid}/covers/card.jpg", ) embed.add_field( name=f"New {ns.name.lower()} map", value=f"[{_map.name}]({_map.url}) is now {ns.name.lower()}!", inline=True, ) wh.add_embed(embed) await wh.post()
async def freeze(self, reason: str, fr: "Player") -> None: expire = datetime.now() + timedelta(days=7) if self.frozen: return # ? self.frozen = True self.freeze_timer = expire.timestamp() await self.add_priv(Privileges.Frozen) await glob.db.execute( "UPDATE users SET freeze_timer = %s WHERE id = %s", [self.freeze_timer, self.id], ) await glob.db.execute( "INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) " "VALUES (%s, %s, %s, %s, %s)", ["freeze", reason, self.id, fr.id, time.time()], ) if self.token: self.enqueue(writer.restartServer(0)) if wh_url := glob.config.webhooks["anticheat"]: wh = Webhook(url=wh_url) embed = Embed(title="") embed.set_author( url=f"https://{glob.config.domain}/u/{self.id}", icon_url=f"https://a.{glob.config.domain}/{self.id}", name=self.name, ) embed.add_field( name="New frozen user", value=f"{self.name} has been frozen by {fr.name} for {reason}.", inline=True, ) wh.add_embed(embed) await wh.post()
async def ban(self, reason: str, fr: 'Player') -> None: if self.priv & Privileges.Banned: return # ? await self.add_priv(Privileges.Banned) if self.token: self.enqueue(writer.userID(-3)) await glob.db.execute( 'INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) ' 'VALUES (%s, %s, %s, %s, %s)', ['ban', reason, self.id, fr.id, time.time()] ) for mode, stat in self.stats.items(): mode_name = osuModes(mode).name await glob.redis.zrem(f'asahi:leaderboard:{mode_name}', self.id) await glob.redis.zrem(f'asahi:leaderboard:{mode_name}:{self.country_iso}', self.id) stat.rank = 0 stat.country_rank = 0 if (wh_url := glob.config.webhooks['anticheat']): wh = Webhook(url=wh_url) embed = Embed(title=f'') embed.set_author( url=f'https://{glob.config.domain}/u/{self.id}', icon_url=f'https://a.{glob.config.domain}/{self.id}', name=self.name ) embed.add_field( name='New banned user', value=f'{self.name} has been banned by {fr.name} for {reason}.', inline=True ) wh.add_embed(embed) await wh.post()
async def freeze(self, reason: str, fr: 'Player') -> None: expire = datetime.now() + timedelta(days=7) if self.frozen: return # ? self.frozen = True self.freeze_timer = expire await self.add_priv(Privileges.Frozen) await glob.db.execute('UPDATE users SET freeze_timer = %s WHERE id = %s', [self.freeze_timer.timestamp(), self.id]) await glob.db.execute( 'INSERT INTO punishments (`type`, `reason`, `target`, `from`, `time`) ' 'VALUES (%s, %s, %s, %s, %s)', ['freeze', reason, self.id, fr.id, time.time()] ) if self.token: self.enqueue(writer.restartServer(0)) if (wh_url := glob.config.webhooks['anticheat']): wh = Webhook(url=wh_url) embed = Embed(title='') embed.set_author( url=f'https://{glob.config.domain}/u/{self.id}', icon_url=f'https://a.{glob.config.domain}/{self.id}', name=self.name ) embed.add_field( name='New frozen user', value=f'{self.name} has been frozen by {fr.name} for {reason}.', inline=True ) wh.add_embed(embed) await wh.post()
# TODO: runningunderwine support mmatch = await glob.db.fetchall( 'SELECT u.name, h.adapters FROM client_hashes h INNER JOIN users u ON h.userid = u.id WHERE h.userid != %s AND h.adapters = %s', [user_info['id'], client_hashes[1]]) dmatch = await glob.db.fetchall( 'SELECT u.name, h.disk_serial FROM client_hashes h INNER JOIN users u ON h.userid = u.id WHERE h.userid != %s AND h.disk_serial = %s', [user_info['id'], client_hashes[3]]) # no uninstallid check as these are often false, may just make it a flag later on in iteki's life imatch = await glob.db.fetchall( 'SELECT u.name, h.ip FROM client_hashes h INNER JOIN users u ON h.userid = u.id WHERE h.userid != %s AND h.ip = %s', [user_info['id'], ip]) if mmatch: webhook_url = glob.config.webhooks['audit-log'] webhook = Webhook(url=webhook_url) embed = Embed(title=f'') embed.set_author( url=f"https://{glob.config.domain}/u/{user_info['id']}", name=username, icon_url=f"https://a.{glob.config.domain}/{user_info['id']}") thumb_url = f'https://a.{glob.config.domain}/1' embed.set_thumbnail(url=thumb_url) for a in mmatch: unames = [] unames.append(a['name']) embed.add_field( name='New banned user', value= f"{user_info['name']} has been banned for a MAC match ({mmatch['adapters']}) with user(s) {unames}", inline=True)
async def _map(user: Player, args: list) -> str: """Update map statuses on the server""" if len(args) != 2: return 'Please provide the new status & whether we should update the map/set! (!map <rank/love/unrank> <map/set>)' status = args[0] _type = args[1] if status not in ('love', 'rank', 'unrank') or _type not in ('set', 'map'): return 'Invalid syntax! Command: !map <rank/love/unrank> <set/map>' bmap = user.np ns = mapStatuses.from_str(status) if _type == 'map': bmap.status = ns bmap.frozen = True # reset lb cache in case of major status change bmap.lb = None bmap.lb_rx = None bmap.lb_ap = None await bmap.save() glob.cache['maps'][bmap.md5] = bmap else: _set = await glob.db.fetch('SELECT md5 FROM maps WHERE sid = %s', [bmap.sid]) for m in _set: md5 = m['md5'] bm = await Beatmap.from_md5(md5) bm.status = ns bm.frozen = True # reset lb cache in case of major status change bm.lb = None bm.lb_rx = None bm.lb_ap = None await bm.save() glob.cache['maps'][bm.md5] = bm if (wh_url := glob.config.webhooks['maps']): wh = Webhook(url=wh_url) embed = Embed(title='') embed.set_author(url=f'https://{glob.config.domain}/u/{user.id}', name=user.name, icon_url=f'https://a.{glob.config.domain}/{user.id}') embed.set_image( url=f'https://assets.ppy.sh/beatmaps/{bmap.sid}/covers/card.jpg') embed.add_field( name=f'New {ns.name.lower()} map', value=f'[{bmap.name}]({bmap.url}) is now {ns.name.lower()}!', inline=True) wh.add_embed(embed) await wh.post()
return 'You must provide what status you want the map to be!' if not (_map := user.np): return 'Please /np the map you want to request first!' if _map.status == mapStatuses.Ranked: return 'This map is already ranked!' ns = mapStatuses.from_str(args[0]) await glob.db.execute( 'INSERT IGNORE INTO requests (requester, map, status, mode) VALUES (%s, %s, %s, %s)', [user.name, user.np.id, int(ns), user.mode_vn]) if (wh_url := glob.config.webhooks['requests']): wh = Webhook(url=wh_url) embed = Embed(title='') embed.set_author(url=f'https://{glob.config.domain}/u/{user.id}', name=user.name, icon_url=f'https://a.{glob.config.domain}/{user.id}') embed.set_image( url=f'https://assets.ppy.sh/beatmaps/{_map.sid}/covers/card.jpg') embed.add_field( name='New request', value= f'{user.name} requested [{_map.name}]({_map.url}) to be {ns.name.lower()}', inline=True)
async def _map(user: Player, args: list) -> str: """Update map statuses on the server""" if len(args) != 2: return "Please provide the new status & whether we should update the map/set! (!map <rank/love/unrank> <map/set>)" status = args[0] _type = args[1] if status not in ("love", "rank", "unrank") or _type not in ("set", "map"): return "Invalid syntax! Command: !map <rank/love/unrank> <set/map>" bmap = user.np ns = mapStatuses.from_str(status) if _type == "map": bmap.status = ns bmap.frozen = True # reset lb cache in case of major status change bmap.lb = None bmap.lb_rx = None bmap.lb_ap = None await bmap.save() glob.cache["maps"][bmap.md5] = bmap else: _set = await glob.db.fetch("SELECT md5 FROM maps WHERE sid = %s", [bmap.sid]) for m in _set: md5 = m["md5"] bm = await Beatmap.from_md5(md5) bm.status = ns bm.frozen = True # reset lb cache in case of major status change bm.lb = None bm.lb_rx = None bm.lb_ap = None await bm.save() glob.cache["maps"][bm.md5] = bm if wh_url := glob.config.webhooks["maps"]: wh = Webhook(url=wh_url) embed = Embed(title="") embed.set_author( url=f"https://{glob.config.domain}/u/{user.id}", name=user.name, icon_url=f"https://a.{glob.config.domain}/{user.id}", ) embed.set_image( url=f"https://assets.ppy.sh/beatmaps/{bmap.sid}/covers/card.jpg", ) embed.add_field( name=f"New {ns.name.lower()} map", value=f"[{bmap.name}]({bmap.url}) is now {ns.name.lower()}!", inline=True, ) wh.add_embed(embed) await wh.post()