def send_message(self, text): my_username = config.sections["server"]["login"] if text[:4] == "/me ": line = "* %s %s" % (my_username, text[4:]) usertag = tag = self.tag_action else: tag = self.tag_local usertag = self.tag_my_username line = "[%s] %s" % (my_username, text) timestamp_format = config.sections["logging"]["private_timestamp"] append_line(self.ChatScroll, line, tag, timestamp_format=timestamp_format, username=my_username, usertag=usertag) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] log.write_log(config.sections["logging"]["privatelogsdir"], self.user, line, timestamp_format)
def send_message(self, text): my_username = self.frame.np.login_username if text.startswith("/me "): line = "* %s %s" % (my_username, text[4:]) tag = self.tag_action else: line = "[%s] %s" % (my_username, text) tag = self.tag_local self.chat_textview.append_line( line, tag, timestamp_format=config.sections["logging"]["private_timestamp"], username=my_username, usertag=self.tag_my_username) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] self.chats.history.update_user( self.user, "%s %s" % (time.strftime(timestamp_format), line)) log.write_log(config.sections["logging"]["privatelogsdir"], self.user, line, timestamp_format=timestamp_format)
def send_message(self, text, bytestring=False): if not self.chats.connected: return user_text = self.frame.np.pluginhandler.outgoing_private_chat_event( self.user, text) if user_text is None: return (u, text) = user_text my_username = config.sections["server"]["login"] if text[:4] == "/me ": line = "* %s %s" % (my_username, text[4:]) usertag = tag = self.tag_me else: if text == self.chats.CTCP_VERSION: line = "CTCP VERSION" else: line = text tag = self.tag_local usertag = self.tag_my_username line = "[%s] %s" % (my_username, line) timestamp_format = config.sections["logging"]["private_timestamp"] append_line(self.ChatScroll, line, tag, timestamp_format=timestamp_format, username=my_username, usertag=usertag) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] log.write_log(config.sections["logging"]["privatelogsdir"], self.user, line, timestamp_format) if bytestring: payload = text else: payload = auto_replace(text) if self.PeerPrivateMessages.get_active(): # not in the soulseek protocol self.frame.np.send_message_to_peer( self.user, slskmessages.PMessageUser(None, my_username, payload)) else: self.frame.np.queue.append( slskmessages.MessageUser(self.user, payload)) self.frame.np.pluginhandler.outgoing_private_chat_notification( self.user, text)
def message_user(self, msg): text = msg.msg newmessage = msg.newmessage timestamp = msg.timestamp if text[:4] == "/me ": line = "* %s %s" % (self.user, text[4:]) tag = self.tag_action else: line = "[%s] %s" % (self.user, text) tag = self.tag_remote timestamp_format = config.sections["logging"]["private_timestamp"] if not newmessage and not self.offlinemessage: append_line( self.ChatScroll, _("* Message(s) sent while you were offline. Timestamps are reported by the server and can be off." ), self.tag_hilite, timestamp_format=timestamp_format) self.offlinemessage = True if newmessage and self.offlinemessage: self.offlinemessage = False if not newmessage: # The timestamps from the server are off by a lot, so we'll only use them when this is an offline message # Also, they are in UTC so we need to correct them if daylight: timestamp -= (3600 * daylight) else: timestamp += altzone append_line(self.ChatScroll, line, self.tag_hilite, timestamp=timestamp, timestamp_format=timestamp_format, username=self.user, usertag=self.tag_username) else: append_line(self.ChatScroll, line, tag, timestamp_format=timestamp_format, username=self.user, usertag=self.tag_username) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] log.write_log(config.sections["logging"]["privatelogsdir"], self.user, line, timestamp_format)
def message_user(self, msg): text = msg.msg newmessage = msg.newmessage timestamp = msg.timestamp if not newmessage else None usertag = self.tag_username self.show_notification(text) if text.startswith("/me "): line = "* %s %s" % (self.user, text[4:]) tag = self.tag_action speech = line[2:] else: line = "[%s] %s" % (self.user, text) tag = self.tag_remote speech = text timestamp_format = config.sections["logging"]["private_timestamp"] if not newmessage: tag = usertag = self.tag_hilite if not self.offline_message: self.chat_textview.append_line( _("* Message(s) sent while you were offline."), tag, timestamp_format=timestamp_format) self.offline_message = True else: self.offline_message = False self.chat_textview.append_line(line, tag, timestamp=timestamp, timestamp_format=timestamp_format, username=self.user, usertag=usertag) if self.Speech.get_active(): self.frame.np.notifications.new_tts( config.sections["ui"]["speechprivate"], { "user": self.user, "message": speech }) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] self.chats.history.update_user( self.user, "%s %s" % (time.strftime(timestamp_format), line)) log.write_log(config.sections["logging"]["privatelogsdir"], self.user, line, timestamp, timestamp_format)
def say_chat_room(self, msg, text, public=False): user = msg.user if self.frame.np.network_filter.is_user_ignored(user): return if self.frame.np.network_filter.is_user_ip_ignored(user): return text = re.sub("\\s\\s+", " ", text) login = config.sections["server"]["login"] if user == login: tag = self.tag_local elif text.upper().find(login.upper()) > -1: tag = self.tag_hilite else: tag = self.tag_remote self.show_notification(login, user, text, tag) if text[:4] == "/me ": if public: line = "%s | * %s %s" % (msg.room, user, text[4:]) else: line = "* %s %s" % (user, text[4:]) speech = line[2:] tag = self.tag_me else: if public: line = "%s | [%s] %s" % (msg.room, user, text) else: line = "[%s] %s" % (user, text) speech = text line = "\n-- ".join(line.split("\n")) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] log.write_log(config.sections["logging"]["roomlogsdir"], self.room, line, timestamp_format) self.get_user_tag(user) timestamp_format = config.sections["logging"]["rooms_timestamp"] if user != login: append_line(self.ChatScroll, censor_chat(line), tag, username=user, usertag=self.tag_users[user], timestamp_format=timestamp_format) if self.Speech.get_active(): self.frame.notifications.new_tts( config.sections["ui"]["speechrooms"] % { "room": self.room, "user": self.frame.notifications.tts_clean(user), "message": self.frame.notifications.tts_clean(speech) }) else: append_line(self.ChatScroll, line, tag, username=user, usertag=self.tag_users[user], timestamp_format=timestamp_format)
def show_message(self, text, newmessage=True, timestamp=None): if text[:4] == "/me ": line = "* %s %s" % (self.user, censor_chat(text[4:])) speech = line[2:] tag = self.tag_me else: line = "[%s] %s" % (self.user, censor_chat(text)) speech = censor_chat(text) tag = self.tag_remote timestamp_format = config.sections["logging"]["private_timestamp"] if not newmessage and not self.offlinemessage: append_line( self.ChatScroll, _("* Message(s) sent while you were offline. Timestamps are reported by the server and can be off." ), self.tag_hilite, timestamp_format=timestamp_format) self.offlinemessage = True if newmessage and self.offlinemessage: self.offlinemessage = False if not newmessage: # The timestamps from the server are off by a lot, so we'll only use them when this is an offline message # Also, they are in UTC so we need to correct them if daylight: timestamp -= (3600 * daylight) else: timestamp += altzone append_line(self.ChatScroll, line, self.tag_hilite, timestamp=timestamp, timestamp_format=timestamp_format, username=self.user, usertag=self.tag_username) else: append_line(self.ChatScroll, line, tag, timestamp_format=timestamp_format, username=self.user, usertag=self.tag_username) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] log.write_log(config.sections["logging"]["privatelogsdir"], self.user, line, timestamp_format) autoreply = config.sections["server"]["autoreply"] if self.frame.away and not self.autoreplied and autoreply: self.send_message("[Auto-Message] %s" % autoreply) self.autoreplied = True self.frame.notifications.new_tts( config.sections["ui"]["speechprivate"] % { "user": self.frame.notifications.tts_clean(self.user), "message": self.frame.notifications.tts_clean(speech) })
def say_chat_room(self, msg, public=False): user = msg.user if self.frame.np.network_filter.is_user_ignored(user): return if self.frame.np.network_filter.is_user_ip_ignored(user): return login_username = self.frame.np.login_username text = msg.msg if user == login_username: tag = self.tag_local elif self.find_whole_word(login_username.lower(), text.lower()) > -1: tag = self.tag_hilite else: tag = self.tag_remote if text.startswith("/me "): tag = self.tag_action line = "* %s %s" % (user, text[4:]) speech = line[2:] else: line = "[%s] %s" % (user, text) speech = text if public: line = "%s | %s" % (msg.room, line) line = "\n-- ".join(line.split("\n")) usertag = self.get_user_tag(user) timestamp_format = config.sections["logging"]["rooms_timestamp"] if user != login_username: self.chat_textview.append_line( self.frame.np.privatechats.censor_chat(line), tag, username=user, usertag=usertag, timestamp_format=timestamp_format) if self.Speech.get_active(): self.frame.np.notifications.new_tts( config.sections["ui"]["speechrooms"], { "room": msg.room, "user": user, "message": speech }) else: self.chat_textview.append_line(line, tag, username=user, usertag=usertag, timestamp_format=timestamp_format) self.show_notification(login_username, user, speech, tag, public) if self.Log.get_active(): timestamp_format = config.sections["logging"]["log_timestamp"] log.write_log(config.sections["logging"]["roomlogsdir"], self.room, line, timestamp_format=timestamp_format)