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 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 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()
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) webhook.add_embed(embed) await webhook.post() if not (t := await glob.players.get(name=username, sql=True)): return f'"{username}" not found.' reason = f'Matching MAC hash with user(s) {unames}' await t.ban(p, reason) if dmatch: 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']}",
embed = Embed( title = f'[{score.mode!r}] Abnormally low presstimes detected' ) embed.set_author( url = player.url, name = player.name, icon_url = player.avatar_url ) embed.set_thumbnail(url=glob.config.webhooks['thumbnail']) for key, pt in press_times.items(): embed.add_field( name = f'Key: {key.name}', value = f'{sum(pt) / len(pt):.2f}ms' if pt else 'N/A', inline = True ) webhook.add_embed(embed) await webhook.post(glob.http) REPLAYS_PATH = Path.cwd() / '.data/osr' async def replay_detections() -> None: """Actively run a background thread throughout gulag's lifespan; it will pull replays determined as sketch from a queue indefinitely.""" glob.sketchy_queue = asyncio.Queue() # cursed type hint fix queue: asyncio.Queue['Score'] = glob.sketchy_queue loop = asyncio.get_running_loop()
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()
[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) wh.add_embed(embed) await wh.post() return 'Request sent!' @command(priv=Privileges.Admin, name='ban') async def ban(user: Player, args: list) -> str: """Ban a specified user for a specified reason""" if len(args) < 2: return 'You must provide a user and a reason to ban!'
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()
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, ) wh.add_embed(embed) await wh.post() return "Request sent!" @command(priv=Privileges.Admin, name="ban") async def ban(user: Player, args: list) -> str: """Ban a specified user for a specified reason""" if len(args) < 2: return "You must provide a user and a reason to ban!"