2016-03-29 11:56:58 +00:00
|
|
|
import uuid
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import IRCBuffer, IRCObject, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-10-01 12:48:55 +00:00
|
|
|
class User(IRCObject.Object):
|
2018-08-18 23:19:53 +00:00
|
|
|
def __init__(self, nickname, id, server, bot):
|
2018-09-11 09:15:16 +00:00
|
|
|
self.server = server
|
2016-03-29 11:56:58 +00:00
|
|
|
self.set_nickname(nickname)
|
2018-09-05 12:00:04 +00:00
|
|
|
self._id = id
|
2016-03-29 11:56:58 +00:00
|
|
|
self.username = None
|
|
|
|
self.hostname = None
|
2017-07-16 20:18:58 +00:00
|
|
|
self.realname = None
|
2016-03-29 11:56:58 +00:00
|
|
|
self.bot = bot
|
|
|
|
self.channels = set([])
|
2018-09-05 10:58:10 +00:00
|
|
|
|
2018-09-04 08:18:14 +00:00
|
|
|
self.identified_account = None
|
2018-09-05 10:58:10 +00:00
|
|
|
self.identified_account_override = None
|
|
|
|
|
|
|
|
self.identified_account_id = None
|
|
|
|
self.identified_account_id_override = None
|
2018-09-04 09:15:20 +00:00
|
|
|
self.away = False
|
2018-09-11 09:15:16 +00:00
|
|
|
self.buffer = IRCBuffer.Buffer(bot, server)
|
2018-08-28 11:23:57 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "IRCUser.User(%s|%s)" % (self.server.name, self.name)
|
2018-10-01 12:48:55 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.nickname
|
2018-08-28 11:23:57 +00:00
|
|
|
|
2018-09-05 11:58:12 +00:00
|
|
|
def get_id(self):
|
2018-09-05 10:58:10 +00:00
|
|
|
return (self.identified_account_id_override or
|
2018-09-05 11:58:12 +00:00
|
|
|
self.identified_account_id or self._id)
|
2018-09-06 17:06:29 +00:00
|
|
|
def get_identified_account(self):
|
|
|
|
return (self.identified_account_override or self.identified_account)
|
2018-09-05 10:58:10 +00:00
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
def set_nickname(self, nickname):
|
|
|
|
self.nickname = nickname
|
2018-10-03 12:22:37 +00:00
|
|
|
self.nickname_lower = utils.irc.lower(self.server, nickname)
|
2016-03-29 11:56:58 +00:00
|
|
|
self.name = self.nickname_lower
|
|
|
|
def join_channel(self, channel):
|
|
|
|
self.channels.add(channel)
|
|
|
|
def part_channel(self, channel):
|
|
|
|
self.channels.remove(channel)
|
|
|
|
def set_setting(self, setting, value):
|
2018-09-05 11:58:12 +00:00
|
|
|
self.bot.database.user_settings.set(self.get_id(), setting, value)
|
2016-03-29 11:56:58 +00:00
|
|
|
def get_setting(self, setting, default=None):
|
2018-09-05 11:58:12 +00:00
|
|
|
return self.bot.database.user_settings.get(self.get_id(), setting,
|
2018-08-18 23:19:53 +00:00
|
|
|
default)
|
2016-03-29 11:56:58 +00:00
|
|
|
def find_settings(self, pattern, default=[]):
|
2018-09-05 11:58:12 +00:00
|
|
|
return self.bot.database.user_settings.find(self.get_id(), pattern,
|
2018-08-18 23:19:53 +00:00
|
|
|
default)
|
2018-08-03 12:43:45 +00:00
|
|
|
def find_settings_prefix(self, prefix, default=[]):
|
2018-09-05 11:58:12 +00:00
|
|
|
return self.bot.database.user_settings.find_prefix(self.get_id(),
|
2018-08-18 23:19:53 +00:00
|
|
|
prefix, default)
|
2016-03-29 11:56:58 +00:00
|
|
|
def del_setting(self, setting):
|
2018-09-05 11:58:12 +00:00
|
|
|
self.bot.database.user_settings.delete(self.get_id(), setting)
|
2018-08-05 16:16:15 +00:00
|
|
|
def get_channel_settings_per_setting(self, setting, default=[]):
|
2018-08-05 21:41:38 +00:00
|
|
|
return self.bot.database.user_channel_settings.find_by_setting(
|
2018-09-05 11:58:12 +00:00
|
|
|
self.get_id(), setting, default)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-10-01 16:26:31 +00:00
|
|
|
def send_message(self, message, prefix=None, tags={}):
|
|
|
|
self.server.send_message(self.nickname, message, prefix=prefix,
|
|
|
|
tags=tags)
|
2016-03-29 11:56:58 +00:00
|
|
|
def send_notice(self, message):
|
|
|
|
self.server.send_notice(self.nickname, message)
|
|
|
|
def send_ctcp_response(self, command, args):
|
|
|
|
self.send_notice("\x01%s %s\x01" % (command, args))
|