def handle_cmd_logout(self, conn, **kwargs): params = kwargs['params'] if len(params) != 0: raise CmdException('.logout') user = self.get_auth(kwargs['sender']) if user == None: raise CmdException('Not logged in') self.auths.pop(kwargs['sender']['data'].lower()) conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_unbanuser(self, conn, **kwargs): params = kwargs['params'] if len(params) != 2: raise CmdException('.unbanuser user permission') try: user = self.users[params[0]] except KeyError: raise CmdException("User doesn't exist") user['banned'].remove(params[1]) self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_setparent(self, conn, **kwargs): params = kwargs['params'] if len(params) != 2: raise CmdException('.setparent group parent') try: group = self.groups[params[0]] except KeyError: raise CmdException("Group doesn't exist") group['parent'] = params[1] self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_setgroup(self, conn, **kwargs): params = kwargs['params'] if len(params) != 2: raise CmdException('.setgroup user group') try: user = self.users[params[0]] except KeyError: raise CmdException("User doesn't exist") user['group'] = params[1] self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_unbangroup(self, conn, **kwargs): params = kwargs['params'] if len(params) != 2: raise CmdException('.unbangroup group permission') try: group = self.groups[params[0]] except KeyError: raise CmdException("Group doesn't exist") group['banned'].remove(params[1]) self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_setpassword(self, conn, **kwargs): params = kwargs['params'] if len(params) != 2: raise CmdException('.setpassword user password') try: user = self.users[params[0]] except KeyError: raise CmdException("User doesn't exist") passhash = self.hash_password(params[1]) user['password'] = passhash self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_part(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.part #channel') conn.msg_part(params[0])
def handle_cmd_join(self, conn, **kwargs): params = kwargs['params'] if len(params) < 1: raise CmdException('.join #channel [password]') conn.msg_join(params[0], params.get[1] if len(params) >= 2 else '')
def handle_cmd_changepassword(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.changepassword newpassword') user = self.get_auth(kwargs['sender']) user = self.users.get(user, None) if user == None: raise CmdException('Not logged in') passhash = self.hash_password(params[0]) user['password'] = passhash self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_creategroup(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.creategroup group') if params[0] in self.groups: raise CmdException('Group already exists') self.groups[params[0]] = { 'granted': set(), 'banned': set(), 'parent': None, } self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_listuserperms(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.listuserperms user') try: user = self.users[params[0]] except KeyError: raise CmdException("User doesn't exist") granted = ', '.join(user['granted']) banned = ', '.join(user['banned']) conn.msg_privmsg(kwargs['respond'], 'User permissions: {}'.format(granted)) conn.msg_privmsg(kwargs['respond'], 'Banned commands: {}'.format(banned))
def permission_required_wrapper(self, **kwargs): user = kwargs['sender'] perm_serv = self.bot.get_service('permission') if perm_serv.has_permission(user, permission): func(self, **kwargs) else: raise CmdException('Permission ' + permission + ' is required')
def handle_cmd_login(self, conn, **kwargs): params = kwargs['params'] if len(params) != 2: raise CmdException('.login username password') try: user = self.users[params[0]] except KeyError: raise CmdException("User doesn't exist") passhash = self.hash_password(params[1]) if passhash == user['password']: self.auths[kwargs['sender']['data'].lower()] = params[0] conn.msg_privmsg(kwargs['respond'], 'Done') else: conn.msg_privmsg(kwargs['respond'], 'Wrong password')
def handle_cmd_listgroupperms(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.listgroupperms group') try: group = self.groups[params[0]] except KeyError: raise CmdException("Group doesn't exist") granted = ', '.join(group['granted']) banned = ', '.join(group['banned']) conn.msg_privmsg(kwargs['respond'], 'Group permissions: {}'.format(granted)) conn.msg_privmsg(kwargs['respond'], 'Banned commands: {}'.format(banned))
def handle_cmd_nick(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.nick newnick') self.bot.nick = params[0] for conn in self.bot.connections: conn.msg_nick(params[0])
def handle_cmd_createuser(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.createuser user') if params[0] in self.users: raise CmdException('User already exists') self.users[params[0]] = { 'granted': set(), 'banned': set(), 'password': None, 'group': None, 'hosts': set() } self.save() conn.msg_privmsg(kwargs['respond'], 'Done')
def handle_cmd_loadmodule(self, conn, **kwargs): params = kwargs['params'] if len(params) != 1: raise CmdException('.loadmodule module') name = params[0] try: module = importlib.import_module(name.lower()) imp.reload(module) except ImportError as e: raise CmdException('Failed to load the module: ' + str(e)) module_class = module.__dict__.get(name, None) if module_class == None: raise CmdException("Module doesn't have the class") for installed_module in self.bot.modules[:]: if installed_module.__class__.__name__ == name: self.bot.uninstall_module(installed_module) self.bot.install_module(module_class)