Don't use IRCUser.id ever, use IRCUser.get_id()
This commit is contained in:
parent
ec119e3dcf
commit
f2aeaf7797
7 changed files with 20 additions and 21 deletions
|
@ -160,7 +160,7 @@ class Server(object):
|
||||||
|
|
||||||
def change_user_nickname(self, old_nickname, new_nickname):
|
def change_user_nickname(self, old_nickname, new_nickname):
|
||||||
user = self.users.pop(old_nickname.lower())
|
user = self.users.pop(old_nickname.lower())
|
||||||
user.id = self.get_user_id(new_nickname)
|
user._id = self.get_user_id(new_nickname)
|
||||||
self.users[new_nickname.lower()] = user
|
self.users[new_nickname.lower()] = user
|
||||||
def has_channel(self, channel_name):
|
def has_channel(self, channel_name):
|
||||||
return channel_name[0] in self.channel_types and channel_name.lower(
|
return channel_name[0] in self.channel_types and channel_name.lower(
|
||||||
|
|
16
IRCUser.py
16
IRCUser.py
|
@ -23,9 +23,9 @@ class User(object):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "IRCUser.User(%s|%s)" % (self.server.name, self.name)
|
return "IRCUser.User(%s|%s)" % (self.server.name, self.name)
|
||||||
|
|
||||||
def _get_id(self):
|
def get_id(self):
|
||||||
return (self.identified_account_id_override or
|
return (self.identified_account_id_override or
|
||||||
self.identified_account_id or self.id)
|
self.identified_account_id or self._id)
|
||||||
|
|
||||||
def set_nickname(self, nickname):
|
def set_nickname(self, nickname):
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
|
@ -36,21 +36,21 @@ class User(object):
|
||||||
def part_channel(self, channel):
|
def part_channel(self, channel):
|
||||||
self.channels.remove(channel)
|
self.channels.remove(channel)
|
||||||
def set_setting(self, setting, value):
|
def set_setting(self, setting, value):
|
||||||
self.bot.database.user_settings.set(self._get_id(), setting, value)
|
self.bot.database.user_settings.set(self.get_id(), setting, value)
|
||||||
def get_setting(self, setting, default=None):
|
def get_setting(self, setting, default=None):
|
||||||
return self.bot.database.user_settings.get(self._get_id(), setting,
|
return self.bot.database.user_settings.get(self.get_id(), setting,
|
||||||
default)
|
default)
|
||||||
def find_settings(self, pattern, default=[]):
|
def find_settings(self, pattern, default=[]):
|
||||||
return self.bot.database.user_settings.find(self._get_id(), pattern,
|
return self.bot.database.user_settings.find(self.get_id(), pattern,
|
||||||
default)
|
default)
|
||||||
def find_settings_prefix(self, prefix, default=[]):
|
def find_settings_prefix(self, prefix, default=[]):
|
||||||
return self.bot.database.user_settings.find_prefix(self._get_id(),
|
return self.bot.database.user_settings.find_prefix(self.get_id(),
|
||||||
prefix, default)
|
prefix, default)
|
||||||
def del_setting(self, setting):
|
def del_setting(self, setting):
|
||||||
self.bot.database.user_settings.delete(self._get_id(), setting)
|
self.bot.database.user_settings.delete(self.get_id(), setting)
|
||||||
def get_channel_settings_per_setting(self, setting, default=[]):
|
def get_channel_settings_per_setting(self, setting, default=[]):
|
||||||
return self.bot.database.user_channel_settings.find_by_setting(
|
return self.bot.database.user_channel_settings.find_by_setting(
|
||||||
self._get_id(), setting, default)
|
self.get_id(), setting, default)
|
||||||
|
|
||||||
def send_message(self, message, prefix=None):
|
def send_message(self, message, prefix=None):
|
||||||
self.server.send_message(self.nickname, message, prefix=prefix)
|
self.server.send_message(self.nickname, message, prefix=prefix)
|
||||||
|
|
|
@ -156,7 +156,7 @@ class Module(object):
|
||||||
"" if coin_bet == 1 else "s"))
|
"" if coin_bet == 1 else "s"))
|
||||||
|
|
||||||
def send(self, event):
|
def send(self, event):
|
||||||
if event["user"].nickname_lower == event["args_split"][0].lower():
|
if event["user"].get_id() == event["args_split"][0].get_id():
|
||||||
event["stderr"].write("You can't send coins to yourself")
|
event["stderr"].write("You can't send coins to yourself")
|
||||||
return
|
return
|
||||||
send_amount = event["args_split"][1]
|
send_amount = event["args_split"][1]
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Module(object):
|
||||||
def duck_bef(self, event):
|
def duck_bef(self, event):
|
||||||
user = event["user"]
|
user = event["user"]
|
||||||
target = user.nickname
|
target = user.nickname
|
||||||
id = user.id
|
id = user.get_id()
|
||||||
|
|
||||||
active_duck = event["target"].get_setting("active-duck", False)
|
active_duck = event["target"].get_setting("active-duck", False)
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ class Module(object):
|
||||||
def duck_bang(self, event):
|
def duck_bang(self, event):
|
||||||
user = event["user"]
|
user = event["user"]
|
||||||
target = user.nickname
|
target = user.nickname
|
||||||
id = user.id
|
id = user.get_id()
|
||||||
if not event["target"].get_setting("active-duck", False):
|
if not event["target"].get_setting("active-duck", False):
|
||||||
event["stderr"].set_prefix("Kick")
|
event["stderr"].set_prefix("Kick")
|
||||||
if event["server"].has_user(target):
|
if event["server"].has_user(target):
|
||||||
|
@ -224,7 +224,7 @@ class Module(object):
|
||||||
user = event["user"]
|
user = event["user"]
|
||||||
channel = event["target"].name
|
channel = event["target"].name
|
||||||
nick = user.nickname
|
nick = user.nickname
|
||||||
id = user.id
|
id = user.get_id()
|
||||||
|
|
||||||
poached = user.get_channel_settings_per_setting("ducks-shot", []
|
poached = user.get_channel_settings_per_setting("ducks-shot", []
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Module(object):
|
||||||
|
|
||||||
def my_id(self, event):
|
def my_id(self, event):
|
||||||
event["stdout"].write("%s: %d" % (event["user"].nickname,
|
event["stdout"].write("%s: %d" % (event["user"].nickname,
|
||||||
event["user"].id))
|
event["user"].get_id()))
|
||||||
|
|
||||||
def channel_id(self, event):
|
def channel_id(self, event):
|
||||||
event["stdout"].write("%s: %d" % (event["target"].name,
|
event["stdout"].write("%s: %d" % (event["target"].name,
|
||||||
|
|
|
@ -11,20 +11,20 @@ class Module(object):
|
||||||
channel_only=True, usage="<username> <message>")
|
channel_only=True, usage="<username> <message>")
|
||||||
|
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
messages = event["channel"].get_user_setting(event["user"].id,
|
messages = event["channel"].get_user_setting(event["user"].get_id(),
|
||||||
"to", [])
|
"to", [])
|
||||||
for nickname, message in messages:
|
for nickname, message in messages:
|
||||||
event["channel"].send_message("%s: <%s> %s" % (
|
event["channel"].send_message("%s: <%s> %s" % (
|
||||||
event["user"].nickname, nickname, message))
|
event["user"].nickname, nickname, message))
|
||||||
if messages:
|
if messages:
|
||||||
event["channel"].del_user_setting(event["user"].id, "to")
|
event["channel"].del_user_setting(event["user"].get_id(), "to")
|
||||||
|
|
||||||
def to(self, event):
|
def to(self, event):
|
||||||
target_user = event["server"].get_user(event["args_split"][0])
|
target_user = event["server"].get_user(event["args_split"][0])
|
||||||
messages = event["target"].get_user_setting(target_user.id,
|
messages = event["target"].get_user_setting(target_user.get_id(),
|
||||||
"to", [])
|
"to", [])
|
||||||
messages.append([event["user"].nickname,
|
messages.append([event["user"].nickname,
|
||||||
" ".join(event["args_split"][1:])])
|
" ".join(event["args_split"][1:])])
|
||||||
event["target"].set_user_setting(target_user.id,
|
event["target"].set_user_setting(target_user.get_id(),
|
||||||
"to", messages)
|
"to", messages)
|
||||||
event["stdout"].write("Message saved")
|
event["stdout"].write("Message saved")
|
||||||
|
|
|
@ -25,15 +25,14 @@ class Module(object):
|
||||||
words = list(filter(None, event["message_split"]))
|
words = list(filter(None, event["message_split"]))
|
||||||
word_count = len(words)
|
word_count = len(words)
|
||||||
|
|
||||||
user_words = event["channel"].get_user_setting(user.id,
|
user_words = event["channel"].get_user_setting(user.get_id(),
|
||||||
"words", 0)
|
"words", 0)
|
||||||
user_words += word_count
|
user_words += word_count
|
||||||
|
|
||||||
if user.get_setting("first-words", None) == None:
|
if user.get_setting("first-words", None) == None:
|
||||||
user.set_setting("first-words", time.time())
|
user.set_setting("first-words", time.time())
|
||||||
|
|
||||||
event["channel"].set_user_setting(user.id,
|
event["channel"].set_user_setting(user.get_id(), "words", user_words)
|
||||||
"words", user_words)
|
|
||||||
|
|
||||||
tracked_words = set(event["server"].get_setting(
|
tracked_words = set(event["server"].get_setting(
|
||||||
"tracked-words", []))
|
"tracked-words", []))
|
||||||
|
|
Loading…
Reference in a new issue