Don't use IRCUser.id ever, use IRCUser.get_id()

This commit is contained in:
jesopo 2018-09-05 12:58:12 +01:00
parent ec119e3dcf
commit f2aeaf7797
7 changed files with 20 additions and 21 deletions

View file

@ -160,7 +160,7 @@ class Server(object):
def change_user_nickname(self, old_nickname, new_nickname):
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
def has_channel(self, channel_name):
return channel_name[0] in self.channel_types and channel_name.lower(

View file

@ -23,9 +23,9 @@ class User(object):
def __repr__(self):
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
self.identified_account_id or self.id)
self.identified_account_id or self._id)
def set_nickname(self, nickname):
self.nickname = nickname
@ -36,21 +36,21 @@ class User(object):
def part_channel(self, channel):
self.channels.remove(channel)
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):
return self.bot.database.user_settings.get(self._get_id(), setting,
return self.bot.database.user_settings.get(self.get_id(), setting,
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)
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)
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=[]):
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):
self.server.send_message(self.nickname, message, prefix=prefix)

View file

@ -156,7 +156,7 @@ class Module(object):
"" if coin_bet == 1 else "s"))
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")
return
send_amount = event["args_split"][1]

View file

@ -124,7 +124,7 @@ class Module(object):
def duck_bef(self, event):
user = event["user"]
target = user.nickname
id = user.id
id = user.get_id()
active_duck = event["target"].get_setting("active-duck", False)
@ -159,7 +159,7 @@ class Module(object):
def duck_bang(self, event):
user = event["user"]
target = user.nickname
id = user.id
id = user.get_id()
if not event["target"].get_setting("active-duck", False):
event["stderr"].set_prefix("Kick")
if event["server"].has_user(target):
@ -224,7 +224,7 @@ class Module(object):
user = event["user"]
channel = event["target"].name
nick = user.nickname
id = user.id
id = user.get_id()
poached = user.get_channel_settings_per_setting("ducks-shot", []
)

View file

@ -11,7 +11,7 @@ class Module(object):
def my_id(self, event):
event["stdout"].write("%s: %d" % (event["user"].nickname,
event["user"].id))
event["user"].get_id()))
def channel_id(self, event):
event["stdout"].write("%s: %d" % (event["target"].name,

View file

@ -11,20 +11,20 @@ class Module(object):
channel_only=True, usage="<username> <message>")
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", [])
for nickname, message in messages:
event["channel"].send_message("%s: <%s> %s" % (
event["user"].nickname, nickname, message))
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):
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", [])
messages.append([event["user"].nickname,
" ".join(event["args_split"][1:])])
event["target"].set_user_setting(target_user.id,
event["target"].set_user_setting(target_user.get_id(),
"to", messages)
event["stdout"].write("Message saved")

View file

@ -25,15 +25,14 @@ class Module(object):
words = list(filter(None, event["message_split"]))
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)
user_words += word_count
if user.get_setting("first-words", None) == None:
user.set_setting("first-words", time.time())
event["channel"].set_user_setting(user.id,
"words", user_words)
event["channel"].set_user_setting(user.get_id(), "words", user_words)
tracked_words = set(event["server"].get_setting(
"tracked-words", []))