ソースを参照

Implement remove_admin()/owner(); fixing some other things.

tags/v0.1^2
Ben Kurtovic 12年前
コミット
d4e9106667
3個のファイルの変更39行の追加4行の削除
  1. +31
    -1
      earwigbot/config/permissions.py
  2. +7
    -2
      earwigbot/irc/connection.py
  3. +1
    -1
      earwigbot/wiki/copyvios/exclusions.py

+ 31
- 1
earwigbot/config/permissions.py ファイルの表示

@@ -27,6 +27,12 @@ from threading import Lock
__all__ = ["PermissionsDB"]

class PermissionsDB(object):
"""
**EarwigBot: Permissions Database Manager**

Controls the :file:`permissions.db` file, which stores the bot's owners and
admins for the purposes of using certain dangerous IRC commands.
"""
ADMIN = 1
OWNER = 2

@@ -68,6 +74,22 @@ class PermissionsDB(object):
query = "INSERT INTO users VALUES (?, ?, ?, ?)"
with sqlite.connect(self._dbfile) as conn, self._db_access_lock:
conn.execute(query, (user.nick, user.ident, user.host, rank))
return user

def _del_rank(self, user, rank):
"""Remove a User from the database."""
query = """DELETE FROM users WHERE user_nick = ? AND user_ident = ? AND
user_host = ? AND user_rank = ?"""
try:
for rule in self._data[rank]:
if user in rule:
with self._db_access_lock:
with sqlite.connect(self._dbfile) as conn:
args = (user.nick, user.ident, user.host, rank)
conn.execute(query, args)
return rule
except KeyError:
return None

def load(self):
"""Load permissions from an existing database, or create a new one."""
@@ -94,13 +116,21 @@ class PermissionsDB(object):
return self._is_rank(user, rank=self.OWNER)

def add_admin(self, nick="*", ident="*", host="*"):
"""Add an nick/ident/host combo to the bot admins list."""
"""Add a nick/ident/host combo to the bot admins list."""
return self._set_rank(_User(nick, ident, host), rank=self.ADMIN)

def add_owner(self, nick="*", ident="*", host="*"):
"""Add a nick/ident/host combo to the bot owners list."""
return self._set_rank(_User(nick, ident, host), rank=self.OWNER)

def remove_admin(self, nick="*", ident="*", host="*"):
"""Remove a nick/ident/host combo to the bot admins list."""
return self._del_rank(_User(nick, ident, host), rank=self.ADMIN)

def remove_owner(self, nick="*", ident="*", host="*"):
"""Remove a nick/ident/host combo to the bot owners list."""
return self._del_rank(_User(nick, ident, host), rank=self.OWNER)

class _User(object):
"""A class that represents an IRC user for the purpose of testing rules."""
def __init__(self, nick, ident, host):


+ 7
- 2
earwigbot/irc/connection.py ファイルの表示

@@ -43,6 +43,7 @@ class IRCConnection(object):
self._send_lock = Lock()

self._last_recv = time()
self._last_send = 0
self._last_ping = 0

def __repr__(self):
@@ -87,6 +88,9 @@ class IRCConnection(object):
def _send(self, msg, hidelog=False):
"""Send data to the server."""
with self._send_lock:
time_since_last = time() - self._last_send
if time_since_last < 0.75:
time.sleep(0.75 - time_since_last)
try:
self._sock.sendall(msg + "\r\n")
except socket.error:
@@ -94,6 +98,7 @@ class IRCConnection(object):
else:
if not hidelog:
self.logger.debug(msg)
self._last_send = time()

def _split(self, msgs, maxlen, maxsplits=3):
"""Split a large message into multiple messages smaller than maxlen."""
@@ -158,7 +163,7 @@ class IRCConnection(object):

def say(self, target, msg, hidelog=False):
"""Send a private message to a target on the server."""
for msg in self._split(msg, 500 - len(target)):
for msg in self._split(msg, 400):
msg = "PRIVMSG {0} :{1}".format(target, msg)
self._send(msg, hidelog)

@@ -177,7 +182,7 @@ class IRCConnection(object):

def notice(self, target, msg, hidelog=False):
"""Send a notice to a target on the server."""
for msg in self._split(msg, 500 - len(target)):
for msg in self._split(msg, 400):
msg = "NOTICE {0} :{1}".format(target, msg)
self._send(msg, hidelog)



+ 1
- 1
earwigbot/wiki/copyvios/exclusions.py ファイルの表示

@@ -44,7 +44,7 @@ class ExclusionsDB(object):
"""
**EarwigBot: Wiki Toolset: Exclusions Database Manager**

Controls the :file:`.exclusions.db` file, which stores URLs excluded from
Controls the :file:`exclusions.db` file, which stores URLs excluded from
copyright violation checks on account of being known mirrors, for example.
"""



読み込み中…
キャンセル
保存