bitbot-3.11-fork/IRCUser.py

61 lines
2.2 KiB
Python
Raw Normal View History

2016-03-29 11:56:58 +00:00
import uuid
import IRCBuffer
2016-03-29 11:56:58 +00:00
class User(object):
def __init__(self, nickname, id, server, bot):
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.server = server
self.bot = bot
self.channels = set([])
self.identified_account = None
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
self.buffer = IRCBuffer.Buffer(bot)
def __repr__(self):
return "IRCUser.User(%s|%s)" % (self.server.name, self.name)
def get_id(self):
return (self.identified_account_id_override or
self.identified_account_id or self._id)
2016-03-29 11:56:58 +00:00
def set_nickname(self, nickname):
self.nickname = nickname
self.nickname_lower = nickname.lower()
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):
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):
return self.bot.database.user_settings.get(self.get_id(), setting,
default)
2016-03-29 11:56:58 +00:00
def find_settings(self, pattern, default=[]):
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(),
prefix, default)
2016-03-29 11:56:58 +00:00
def del_setting(self, 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)
2016-03-29 11:56:58 +00:00
def send_message(self, message, prefix=None):
self.server.send_message(self.nickname, message, prefix=prefix)
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))