async def c_ban_unban(client, data): """.ban [add/del/list] [user] [timer]/.kickban [add/del] [user] [reason] [timer]/.unban [user] -- Ban/kickban/unban the user. User can be banned for [timer]. .unban automatically removes from ban list.""" message = data.split_message conn = client.bot.dbs[data.server] bans = await botu.make_list( db.get_cell(conn, 'channels', 'ban', 'channel', data.target)[0][0]) if data.command == 'unban': asyncio.create_task(client.unban(data.target, message[0])) asyncio.create_task( botu.del_from_channels(client, data, conn, 'ban', message[0], bans, f'Removing {message[0]} from bans.', f'{message[0]} is not in the ban list.')) return try: timer = int(message[-1]) message = message[:-1] except ValueError: timer = 0 if message[0] == 'del': message = message[1:] asyncio.create_task( botu.del_from_channels(client, data, conn, 'ban', message[0], bans, f'Removing {message[0]} from bans.', f'{message[0]} is not in the ban list.')) elif message[0] == 'add': message = message[1:] asyncio.create_task( botu.add_to_channels(client, data, conn, 'ban', message[0], bans, f'Adding {message[0]} to the bans.', f'{message[0]} is already in the ban list.')) elif message[0] == 'list': asyncio.create_task( client.notice(data.nickname, 'bans are: ' + ', '.join(bans))) return if data.command == 'ban': asyncio.create_task(client.ban(data.target, message[0])) if data.command == 'kickban': asyncio.create_task( client.kickban( data.target, message[0], reason=' '.join(message).replace(message[0], 'Git Rekt'))) if timer: asyncio.create_task( timeu.asyncsched(timer, client.unban, (data.target, message[0])))
async def c_admins(client, data): """ .admins [list/add/del] [user/mask] -- Lists, adds or deletes users or masks from admins. """ message = data.split_message conn = client.bot.dbs[data.server] admins = await botu.make_list( db.get_cell(conn, 'channels', 'admins', 'channel', data.target)[0][0]) if len(message) > 1: masks = await user.parse_masks(client, conn, ' '.join(message[1:])) if message[0] == 'del': for mask in masks: asyncio.create_task( botu.del_from_channels(client, data, conn, 'admins', mask, admins, f'Removing {mask} from admins.', f'{mask} is not an admin.')) elif message[0] == 'add': for mask in masks: asyncio.create_task( botu.add_to_channels(client, data, conn, 'admins', mask, admins, f'Adding {mask} to admins.', f'{mask} is already an admin.')) elif message[0] == 'list': if admins: asyncio.create_task( client.notice(data.nickname, f'Admins are: {", ".join(admins)}')) else: asyncio.create_task( client.notice(data.nickname, 'There are no admins.')) return
async def c_enable_disable(client, data): """ .enable/.disable <list/commands/events/sieves> -- Lists, enables or disables commands, events and sieves. """ event_vals = list(client.bot.plugs['event'].values()) events = [func[0].__name__ for func in (event for event in event_vals)] commands = list(client.bot.plugs['command']) sieves = list(client.bot.plugs['sieve']) nodisable = client.bot.config['servers'][data.server]['no_disable'] conn = client.bot.dbs[data.server] disabled = await botu.make_list( db.get_cell(conn, 'channels', 'disabled', 'channel', data.target)[0][0]) message = data.split_message if message[0] == 'list': asyncio.create_task( botu.cmd_event_sieve_lists(client, data, disabled, nodisable, sieves, events, commands)) return for plugin in message: plugin = plugin.lower().strip() if await botu.is_cmd_event_sieve(plugin, data, sieves, events, commands): asyncio.create_task( client.notice(data.nickname, f'{plugin} is not a sieve, command or event.')) elif data.command == 'enable': asyncio.create_task( botu.del_from_channels(client, data, conn, 'disabled', plugin, disabled, f'Enabling {plugin}', f'{plugin} is not disabled')) elif data.command == 'disable': if plugin in nodisable: asyncio.create_task( client.notice(data.nickname, f'You cannot disable {plugin}.')) else: asyncio.create_task( botu.add_to_channels(client, data, conn, 'disabled', plugin, disabled, f'Disabling {plugin}', f'{plugin} is already disabled.'))
async def c_op(client, data): """.deop <users>/.op [add/del/list] [users] -- Ops/deops users and can add/del to autoop list. Same for hop and vop.""" message = data.split_message conn = client.bot.dbs[data.server] if data.command[0:2] == 'de': asyncio.create_task( botu.usermodes(client, data.target, data.command, message)) return dbmasks = await botu.make_list( db.get_cell(conn, 'channels', data.command, 'channel', data.target)[0][0]) if message[0] == 'list': if dbmasks: asyncio.create_task( client.notice(data.nickname, f'{data.command}s are: {" ".join(dbmasks)}.')) else: asyncio.create_task( client.notice(data.nickname, f'There are no {data.command}s.')) return message = message[1:] masks = await user.parse_masks(client, conn, ' '.join(message)) for mask in masks: if message[0] == 'add': asyncio.create_task( botu.add_to_channels( client, data, conn, data.command, mask, dbmasks, f'Adding {mask} to {data.command} list.', f'{mask} is already auto-{data.command}ed.')) elif message[0] == 'del': asyncio.create_task( botu.del_from_channels( client, data, conn, data.command, mask, dbmasks, f'Removing {mask} from {data.command} list.', f'{mask} is not auto-{data.command}ed.')) asyncio.create_task( botu.usermodes(client, data.target, data.command, message))