def kickban(client, arg, ban_hdid): args = shlex.split(arg) if len(args) < 2: raise ArgumentError('Not enough arguments.') elif len(args) == 2: reason = None ban_id = None try: ban_id = int(args[1]) unban_date = None except ValueError: reason = args[1] unban_date = arrow.get().shift(hours=6).datetime elif len(args) == 3: ban_id = None reason = args[1] if 'perma' in args[2]: unban_date = None else: duration = pytimeparse.parse(args[2], granularity='hours') if duration is None: raise ArgumentError('Invalid ban duration.') unban_date = arrow.get().shift(seconds=duration).datetime else: raise ArgumentError( f'Ambiguous input: {arg}\nPlease wrap your arguments ' 'in quotes.') try: raw_ipid = args[0] ipid = int(raw_ipid) except ValueError: raise ClientError(f'{raw_ipid} does not look like a valid IPID.') ban_id = database.ban(ipid, reason, ban_type='ipid', banned_by=client, ban_id=ban_id, unban_date=unban_date) if ipid != None: targets = client.server.client_manager.get_targets( client, TargetType.IPID, ipid, False) if targets: for c in targets: if ban_hdid: database.ban(c.hdid, reason, ban_type='hdid', ban_id=ban_id) c.send_command('KB', reason) c.disconnect() database.log_misc('ban', client, target=c, data={'reason': reason}) client.send_ooc(f'{len(targets)} clients were kicked.') client.send_ooc(f'{ipid} was banned. Ban ID: {ban_id}')
def kickban(client, arg: str, ban_hdid): args = shlex.split(arg) ban_id = None default_ban_duration = client.server.config['default_ban_duration'] if len(args) < 2: raise ArgumentError('Not enough arguments.') elif len(args) == 2: ipid = _convert_ipid_to_int(args[0]) ban_id = args[1] reason = None ban_duration = parse(str(default_ban_duration), granularity='hours') unban_date = arrow.get().shift(hours=ban_duration).datetime elif len(args) == 3: ipid = _convert_ipid_to_int(args[0]) reason = args[1] duration = args[2] ban_duration = parse(str(duration), granularity='hours') if duration is None: raise ArgumentError('Invalid ban duration.') elif 'perma' in duration.lower(): unban_date = None else: if ban_duration is not None: unban_date = arrow.get().shift(hours=ban_duration).datetime else: raise ArgumentError(f'{duration} is an invalid ban duration') else: raise ArgumentError( f'Ambiguous input: {arg}\nPlease wrap your arguments ' 'in quotes.') ban_id = database.ban(ipid, reason, ban_type='ipid', banned_by=client, ban_id=ban_id, unban_date=unban_date) targets = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) if targets: for c in targets: if ban_hdid: database.ban(c.hdid, reason, ban_type='hdid', ban_id=ban_id) c.send_command('KB', reason) c.disconnect() database.log_misc('ban', client, target=c, data={'reason': reason}) client.send_ooc(f'{len(targets)} clients were kicked.') client.send_ooc(f'{ipid} was banned. Ban ID: {ban_id}')
def kickban(client, arg, ban_hdid): args = shlex.split(arg) if len(args) < 2: raise ArgumentError("Not enough arguments.") elif len(args) == 2: reason = None ban_id = None try: ban_id = int(args[1]) unban_date = None except ValueError: reason = args[1] unban_date = arrow.get().shift(hours=6).datetime elif len(args) == 3: ban_id = None reason = args[1] if "perma" in args[2]: unban_date = None else: duration = pytimeparse.parse(args[2], granularity="hours") if duration is None: raise ArgumentError("Invalid ban duration.") unban_date = arrow.get().shift(seconds=duration).datetime else: raise ArgumentError( f"Ambiguous input: {arg}\nPlease wrap your arguments " "in quotes.") try: raw_ipid = args[0] ipid = int(raw_ipid) except ValueError: raise ClientError(f"{raw_ipid} does not look like a valid IPID.") ban_id = database.ban( ipid, reason, ban_type="ipid", banned_by=client, ban_id=ban_id, unban_date=unban_date, ) char = None hdid = None if ipid is not None: targets = client.server.client_manager.get_targets( client, TargetType.IPID, ipid, False) if targets: for c in targets: if ban_hdid: database.ban(c.hdid, reason, ban_type="hdid", ban_id=ban_id) hdid = c.hdid c.send_command("KB", reason) c.disconnect() char = c.char_name database.log_misc("ban", client, target=c, data={"reason": reason}) client.send_ooc(f"{len(targets)} clients were kicked.") client.send_ooc(f"{ipid} was banned. Ban ID: {ban_id}") client.server.webhooks.ban(ipid, ban_id, reason, client, hdid, char, unban_date)
def kickban(client, arg: str, ban_hdid): args = shlex.split(arg) ban_id = None default_ban_duration = client.server.config['default_ban_duration'] if len(args) < 2: raise ArgumentError('Not enough arguments.') elif len(args) == 2: ipid = _convert_ipid_to_int(args[0]) try: ban_id = int(args[1]) reason = None except ValueError: ban_id = None reason = args[1] ban_duration = parse(str(default_ban_duration)) unban_date = arrow.get().shift(seconds=ban_duration).datetime elif len(args) == 3: ipid = _convert_ipid_to_int(args[0]) reason = args[1] duration = args[2] ban_duration = parse(str(duration)) if duration is None: raise ArgumentError('Invalid ban duration.') elif 'perma' in duration.lower(): unban_date = None else: if ban_duration is not None: unban_date = arrow.get().shift(seconds=ban_duration).datetime else: raise ArgumentError(f'{duration} is an invalid ban duration') else: raise ArgumentError(f'Ambiguous input: {arg}\nPlease wrap your arguments ' 'in quotes.') try: raw_ipid = args[0] ipid = int(raw_ipid) except ValueError: raise ClientError(f'{raw_ipid} does not look like a valid IPID.') if ban_id != None: existing_ban = database.find_ban(None, None, ban_id) if existing_ban: if bool(existing_ban.unbanned) == True: raise ClientError(f'{ban_id} is already unbanned.') ban_id = database.ban(ipid, reason, ban_type='ipid', banned_by=client, ban_id=ban_id, unban_date=unban_date) targets = client.server.client_manager.get_targets( client, TargetType.IPID, ipid, False) if targets: for c in targets: if ban_hdid: database.ban(c.hdid, reason, ban_type='hdid', ban_id=ban_id) c.send_command('KB', reason) c.disconnect() database.log_misc('ban', client, target=c, data={'reason': reason}) client.send_ooc(f'{len(targets)} clients were kicked.') client.send_ooc(f'{ipid} was banned. Ban ID: {ban_id}')
def kickban(client, arg, ban_hdid): args = shlex.split(arg) w = Webhooks(client.server) if len(args) < 2: raise ArgumentError('Not enough arguments.') elif len(args) == 2: reason = None ban_id = None try: ban_id = int(args[1]) unban_date = None except ValueError: reason = args[1] unban_date = arrow.get().shift(hours=6).datetime elif len(args) == 3: ban_id = None reason = args[1] if 'perma' in args[2]: unban_date = None else: duration = pytimeparse.parse(args[2], granularity='hours') if duration is None: raise ArgumentError('Invalid ban duration.') unban_date = arrow.get().shift(seconds=duration).datetime else: raise ArgumentError( f'Ambiguous input: {arg}\nPlease wrap your arguments ' 'in quotes.') try: raw_ipid = args[0] ipid = int(raw_ipid) except ValueError: raise ClientError(f'{raw_ipid} does not look like a valid IPID.') modfile = 'config/moderation.yaml' new = not os.path.exists(modfile) if not new: with open(modfile, 'r') as chars: mods = yaml.safe_load(chars) for item in mods: ipids = [] try: ipids = item['ipid'].split() except: ipids.append(item['ipid']) if ipid in ipids: if item['status'] == 'admin': return client.send_ooc('Can\'t ban an admin.') ban_id = database.ban(ipid, reason, ban_type='ipid', banned_by=client, ban_id=ban_id, unban_date=unban_date) if ipid != None: targets = client.server.client_manager.get_targets( client, TargetType.IPID, ipid, False) if targets: for c in targets: if ban_hdid: database.ban(c.hdid, reason, ban_type='hdid', ban_id=ban_id) w.ban(char=c.char_name, ipid=c.ipid, ban_id=ban_id, reason=reason, hdid=c.hdid) else: w.ban(char=c.char_name, ipid=c.ipid, ban_id=ban_id, reason=reason) c.send_command('KB', f'Banned: "{reason}"') c.disconnect() database.log_misc('ban', client, target=c, data={'reason': reason}) client.send_ooc(f'{len(targets)} clients were kicked.') client.send_ooc(f'{ipid} was banned. Ban ID: {ban_id}')