Browse Source

Implement new permissions system in bot commands.

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
bff57f55bc
5 changed files with 10 additions and 8 deletions
  1. +1
    -1
      earwigbot/commands/chanops.py
  2. +1
    -1
      earwigbot/commands/git_command.py
  3. +1
    -1
      earwigbot/commands/quit.py
  4. +1
    -1
      earwigbot/commands/threads.py
  5. +6
    -4
      earwigbot/config/permissions.py

+ 1
- 1
earwigbot/commands/chanops.py View File

@@ -36,7 +36,7 @@ class ChanOps(Command):
de_escalate = data.command in ["devoice", "deop"] de_escalate = data.command in ["devoice", "deop"]
if de_escalate and (not data.args or data.args[0] == data.nick): if de_escalate and (not data.args or data.args[0] == data.nick):
target = data.nick target = data.nick
elif data.host not in self.config.irc["permissions"]["admins"]:
elif not self.config.irc["permissions"].is_admin(data):
self.reply(data, "You must be a bot admin to use this command.") self.reply(data, "You must be a bot admin to use this command.")
return return




+ 1
- 1
earwigbot/commands/git_command.py View File

@@ -39,7 +39,7 @@ class Git(Command):


def process(self, data): def process(self, data):
self.data = data self.data = data
if data.host not in self.config.irc["permissions"]["owners"]:
if not self.config.irc["permissions"].is_owner(data):
msg = "You must be a bot owner to use this command." msg = "You must be a bot owner to use this command."
self.reply(data, msg) self.reply(data, msg)
return return


+ 1
- 1
earwigbot/commands/quit.py View File

@@ -29,7 +29,7 @@ class Quit(Command):
commands = ["quit", "restart", "reload"] commands = ["quit", "restart", "reload"]


def process(self, data): def process(self, data):
if data.host not in self.config.irc["permissions"]["owners"]:
if not self.config.irc["permissions"].is_owner(data):
self.reply(data, "You must be a bot owner to use this command.") self.reply(data, "You must be a bot owner to use this command.")
return return
if data.command == "quit": if data.command == "quit":


+ 1
- 1
earwigbot/commands/threads.py View File

@@ -32,7 +32,7 @@ class Threads(Command):


def process(self, data): def process(self, data):
self.data = data self.data = data
if data.host not in self.config.irc["permissions"]["owners"]:
if not self.config.irc["permissions"].is_owner(data):
msg = "You must be a bot owner to use this command." msg = "You must be a bot owner to use this command."
self.reply(data, msg) self.reply(data, msg)
return return


+ 6
- 4
earwigbot/config/permissions.py View File

@@ -83,13 +83,15 @@ class PermissionsDB(object):
except sqlite.OperationalError: except sqlite.OperationalError:
self._create(conn) self._create(conn)


def is_admin(self, nick="*", ident="*", host="*"):
def is_admin(self, data):
"""Return ``True`` if the given user is a bot admin, else ``False``.""" """Return ``True`` if the given user is a bot admin, else ``False``."""
return self._is_rank(_User(nick, ident, host), rank=self.ADMIN)
user = _User(data.nick, data.ident, data.host)
return self._is_rank(user, rank=self.ADMIN)


def is_owner(self, nick="*", ident="*", host="*"):
def is_owner(self, data):
"""Return ``True`` if the given user is a bot owner, else ``False``.""" """Return ``True`` if the given user is a bot owner, else ``False``."""
return self._is_rank(_User(nick, ident, host), rank=self.OWNER)
user = _User(data.nick, data.ident, data.host)
return self._is_rank(user, rank=self.OWNER)


def add_admin(self, nick="*", ident="*", host="*"): def add_admin(self, nick="*", ident="*", host="*"):
"""Add an nick/ident/host combo to the bot admins list.""" """Add an nick/ident/host combo to the bot admins list."""


Loading…
Cancel
Save