Add a way to not add a user automatically in IRCServer.get_user

This commit is contained in:
jesopo 2018-10-03 11:32:31 +01:00
parent 489d508997
commit 760c9d8844

View file

@ -158,14 +158,14 @@ class Server(IRCObject.Object):
def has_user(self, nickname):
return Utils.irc_lower(self, nickname) in self.users
def get_user(self, nickname):
if not self.has_user(nickname):
def get_user(self, nickname, create=True):
if not self.has_user(nickname) and create:
user_id = self.get_user_id(nickname)
new_user = IRCUser.User(nickname, user_id, self, self.bot)
self.events.on("new.user").call(user=new_user, server=self)
self.users[new_user.nickname_lower] = new_user
self.new_users.add(new_user)
return self.users[Utils.irc_lower(self, nickname)]
return self.users.get(Utils.irc_lower(self, nickname), None)
def get_user_id(self, nickname):
self.bot.database.users.add(self.id, nickname)
return self.bot.database.users.get_id(self.id, nickname)