def log_ctcp(self, full_line, server_obj, user_obj, channel_obj): ctcp_command = full_line.split()[0] ctcp_arguments = ' '.join(full_line.split()[1:]) if ctcp_command.lower() == "action": output = Commons.current_timestamp() + " " output += "**" + user_obj.get_name() + ' ' + ctcp_arguments + '**' return output output = Commons.current_timestamp() + " " output += "<" + user_obj.get_name() + ' (CTCP)> ' + full_line return output
def print_ping(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " if user_obj is None: output += "["+server_obj.get_name() + "] PING" else: output += "["+server_obj.get_name() + "] PONG" return output
def print_kick(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += user_obj.get_name() + " was kicked from " + channel_obj.get_name() if full_line.strip() != "": output += " (" + full_line + ")" return output
def print_quit(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += user_obj.get_name() + " has quit." if full_line.strip() != "": output += " (" + full_line + ")" return output
def print_message(self, full_line, server_obj, user_obj, channel_obj): destination_object = channel_obj if channel_obj is None: destination_object = user_obj output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += destination_object.get_name() + " " output += "<" + user_obj.get_name() + "> " + full_line return output
def print_ctcp(self, full_line, server_obj, user_obj, channel_obj): # Get useful data and objects ctcp_command = full_line.split()[0] ctcp_arguments = ' '.join(full_line.split()[1:]) destination_obj = channel_obj if channel_obj is None: destination_obj = user_obj # Print CTCP actions differently to other CTCP commands if ctcp_command.lower() == "action": output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += destination_obj.get_name() + " " output += "**" + user_obj.get_name() + " " + ctcp_arguments + "**" return output output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += destination_obj.get_name() + " " output += "<" + user_obj.get_name() + " (CTCP)> " + full_line return output
def print_join(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += user_obj.get_name() + " joined " + channel_obj.get_name() return output
def print_day(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "Day changed: "+datetime.datetime.now().strftime("%Y-%m-%d") return output
def print_raw(self, raw_text): output = Commons.current_timestamp() + " " + \ raw_text return output
def print_notice(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += "Notice from " + user_obj.get_name() + ": " + full_line return output
def print_invite(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += "Invite to " + channel_obj.get_name() + ' from ' + user_obj.get_name() return output
def print_name_change(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += "Nick change: " + full_line + " -> " + user_obj.get_name() return output
def log_message(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += '<' + user_obj.get_name() + '> ' + full_line return output
def test_current_timestamp(self): stamp = Commons.current_timestamp() assert len(stamp) == 10, "Timestamp is the wrong length" pattern = re.compile("^\[(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\]$") assert pattern.match(stamp), "Timestamp is not valid to defined format."
def print_mode_change(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += "[" + server_obj.get_name() + "] " output += user_obj.get_name() + ' set ' + full_line + ' on ' + channel_obj.get_name() return output
def test_current_timestamp_datetime_given(self): dtime = datetime(2019, 4, 6, 10, 15, 3) stamp = Commons.current_timestamp(dtime) assert stamp == "[10:15:03]"
def log_leave(self, full_line, server_obj, user_obj, channel_obj): output = Commons.current_timestamp() + " " output += user_obj.get_name() + " left " + channel_obj.get_name() if full_line.strip() != "": output += " (" + full_line + ")" return output