Beispiel #1
0
def sushi_mode(time, server, sender, target, mode, param):
    """ sender can be empty, param can be empty """
    if sender == "":
        # mode listing
        msg = format_message(
            "actions",
            "mode_list", {
                "target": target,
                "mode": mode
            },
            own=(target == main_window.find_server(server).get_nick()),
            highlight=False)
        current_server_tab_print(server, msg)

    else:
        nick = parse_from(sender)[0]
        msg = format_message(
            "actions",
            "mode", {
                "nick": nick,
                "mode": mode,
                "param": param and " " + param or "",
                "target": target
            },
            own=(nick == main_window.find_server(server).get_nick()),
            highlight=(target == main_window.find_server(server).get_nick()))
        msg.markup_cb = color_nick_markup_cb

        tab = main_window.find_tab(server, target)
        print_tab(tab, msg)
Beispiel #2
0
def sushi_dcc_send(time, id, server, sender, filename, size, progress, speed,
                   status):
    """ handle dcc incoming/outgoing """
    # setup function attributes
    self = helper.code.init_function_attrs(sushi_dcc_send, new_register={})

    # import dcc states
    from helper.dcc import s_incoming, s_running, s_new

    logging.debug("dcc_send: (%d,%s,%s,%s)" % (id, server, sender, filename))

    if ("" in (server, sender, filename)
            and 0 in (size, progress, speed, status)):
        # file transfer removed
        logging.debug("filetransfer %d removed." % (id))

    else:
        if status & s_incoming:
            if status & s_new:
                logging.debug("incoming filetransfer (%d): %s %s %s" %
                              (id, server, sender, filename))

                msg = format_message("informative", "dcc_new_incoming", {
                    "sender": sender,
                    "id": id,
                    "filename": filename,
                    "size": size
                })

                if main_window.current_tab:
                    print_tab(main_window.current_tab, msg)
                else:
                    main_window.print_text(unicode(msg))

                self.new_register[id] = True

            elif status & s_running and status & s_incoming:
                if not self.new_register.has_key(id):
                    # notify about auto accepted file transfer
                    msg = format_message("informative", "dcc_file_auto_accept",
                                         {
                                             "sender": sender,
                                             "filename": filename,
                                             "size": size
                                         })

                    if main_window.current_tab:
                        print_tab(main_window.current_tab, msg)
                    else:
                        main_window.print_text(unicode(msg))

                    self.new_register[id] = True
Beispiel #3
0
def sushi_dcc_send(time, id, server, sender, filename,
				size, progress, speed, status):
	""" handle dcc incoming/outgoing """
	# setup function attributes
	self = helper.code.init_function_attrs(sushi_dcc_send, new_register={})

	# import dcc states
	from helper.dcc import s_incoming, s_running, s_new

	logging.debug("dcc_send: (%d,%s,%s,%s)" % (id, server, sender, filename))

	if ("" in (server, sender, filename)
	and 0 in (size, progress, speed, status)):
		# file transfer removed
		logging.debug("filetransfer %d removed." % (id))

	else:
		if status & s_incoming:
			if status & s_new:
				logging.debug("incoming filetransfer (%d): %s %s %s" % (id, server, sender, filename))

				msg = format_message("informative", "dcc_new_incoming",
						{"sender": sender,
						 "id": id,
						 "filename": filename,
   						 "size": size})

				if main_window.current_tab:
					print_tab(main_window.current_tab, msg)
				else:
					main_window.print_text(unicode(msg))

				self.new_register[id] = True

			elif status & s_running and status & s_incoming:
				if not self.new_register.has_key(id):
					# notify about auto accepted file transfer
					msg = format_message(
							"informative",
							"dcc_file_auto_accept",
							{"sender": sender,
							 "filename": filename,
							 "size": size})

					if main_window.current_tab:
						print_tab(main_window.current_tab, msg)
					else:
						main_window.print_text(unicode(msg))

					self.new_register[id] = True
Beispiel #4
0
def sushi_join(time, server, sender, channel):

	server_tab = main_window.find_server(server)

	if not server_tab:
		print_error("Missing server tab for '%s'." % (server))
		return

	tab = main_window.find_tab(server, channel)
	nick = parse_from(sender)[0]

	if nick == server_tab.get_nick():
		# we join
		if not tab:
			tab = tabs.Channel(name = channel, parent = server_tab)

		tab.set_joined(True)
		main_window.update_divider()

	else:
		# somebody joined
		tab.nicklist.add_nick(nick)

	msg = format_message("actions", "join",
		{"nick": nick,
   		 "host": sender,
		 "channel": channel},
		own = (nick == server_tab.get_nick()),
		highlight = False)

	msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)
Beispiel #5
0
def sushi_kick(time, server, sender, channel, who, message):
	""" message can be empty """
	stab = main_window.find_server(server)

	if not stab:
		print_error("missing stab '%s'" % (server))
		return

	nick = parse_from(sender)[0]
	tab = main_window.find_tab(server, channel)

	if who == stab.get_nick():
		# we got kicked
		pass

	else:
		tab.nicklist.remove_nick(who)

	msg = format_message("actions", "kick",
		{"who": who,
		 "channel": channel,
		 "nick": nick,
		 "reason": message},
		own = (who == stab.get_nick()),
		highlight = (nick == tab.parent.get_nick()))
	msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)
Beispiel #6
0
def sushi_topic(time, server, sender, channel, topic):
	""" sender can be empty """
	tab = main_window.find_tab(server, channel)

	if not tab:
		print_error("No tab '%s' on '%s' for topic setting." % (
			channel, server))
		return

	tab.set_topic(topic)
	nick = parse_from(sender)[0]

	if sender == "":
		template = "topic_anonymous"
	else:
		template = "topic"

	msg = format_message("actions", template,
		{"nick": nick,
		 "channel": channel,
		 "topic": topic},
		own = (tab.parent.get_nick() == nick),
		highlight = False)
	if nick:
		msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)

	if tab == main_window.current_tab:
		# update topic bar
		main_window.header.set_text(tab.get_topic())
Beispiel #7
0
def sushi_oper(time, server):
    msg = format_message("actions",
                         "oper",
                         {"nick": main_window.find_server(server).get_nick()},
                         own=True,
                         highlight=False)
    current_server_tab_print(server, msg)
Beispiel #8
0
def sushi_join(time, server, sender, channel):

    server_tab = main_window.find_server(server)

    if not server_tab:
        print_error("Missing server tab for '%s'." % (server))
        return

    tab = main_window.find_tab(server, channel)
    nick = parse_from(sender)[0]

    if nick == server_tab.get_nick():
        # we join
        if not tab:
            tab = tabs.Channel(name=channel, parent=server_tab)

        tab.set_joined(True)
        main_window.update_divider()

    else:
        # somebody joined
        tab.nicklist.add_nick(nick)

    msg = format_message("actions",
                         "join", {
                             "nick": nick,
                             "host": sender,
                             "channel": channel
                         },
                         own=(nick == server_tab.get_nick()),
                         highlight=False)

    msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)
Beispiel #9
0
def sushi_topic(time, server, sender, channel, topic):
    """ sender can be empty """
    tab = main_window.find_tab(server, channel)

    if not tab:
        print_error("No tab '%s' on '%s' for topic setting." %
                    (channel, server))
        return

    tab.set_topic(topic)
    nick = parse_from(sender)[0]

    if sender == "":
        template = "topic_anonymous"
    else:
        template = "topic"

    msg = format_message("actions",
                         template, {
                             "nick": nick,
                             "channel": channel,
                             "topic": topic
                         },
                         own=(tab.parent.get_nick() == nick),
                         highlight=False)
    if nick:
        msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)

    if tab == main_window.current_tab:
        # update topic bar
        main_window.header.set_text(tab.get_topic())
Beispiel #10
0
def sushi_part(time, server, sender, channel, message):
    """ message can be empty """
    tab = main_window.find_tab(server, channel)
    nick = parse_from(sender)[0]

    if not tab:
        # ignore this cause it could be this tab was
        # closed recently
        return

    if tab.parent.get_nick() == nick:
        # we parted
        tab.set_joined(False)
        main_window.update_divider()

    else:
        tab.nicklist.remove_nick(nick)

    msg = format_message("actions",
                         "part", {
                             "nick": nick,
                             "channel": channel,
                             "reason": message
                         },
                         own=(tab.parent.get_nick() == nick),
                         highlight=False)
    msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)
Beispiel #11
0
def sushi_kick(time, server, sender, channel, who, message):
    """ message can be empty """
    stab = main_window.find_server(server)

    if not stab:
        print_error("missing stab '%s'" % (server))
        return

    nick = parse_from(sender)[0]
    tab = main_window.find_tab(server, channel)

    if who == stab.get_nick():
        # we got kicked
        pass

    else:
        tab.nicklist.remove_nick(who)

    msg = format_message("actions",
                         "kick", {
                             "who": who,
                             "channel": channel,
                             "nick": nick,
                             "reason": message
                         },
                         own=(who == stab.get_nick()),
                         highlight=(nick == tab.parent.get_nick()))
    msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)
Beispiel #12
0
def sushi_quit(time, server, sender, message):
	""" message can be empty """
	server_tab = main_window.find_server(server)

	if not server_tab:
		print_error("No server tab for server '%s'." % (server))
		return

	nick = parse_from(sender)[0]

	msg = format_message("actions", "quit",
		{"nick": nick,
		 "reason": message},
		own = (nick == server_tab.get_nick()),
		highlight = False)
	msg.markup_cb = color_nick_markup_cb

	if nick == server_tab.get_nick():
		# we quit
		server_tab.set_connected(False)

		for child in server_tab.children:
			print_tab(child, msg)

	else:
		for tab in server_tab.children:
			if type(tab) == tabs.Channel and tab.nicklist.has_nick(nick):
				tab.nicklist.remove_nick(nick)
				print_tab(tab, msg)
			elif (type(tab) == tabs.Query
				and tab.name.lower() == nick.lower()):
				print_tab(tab, msg)
Beispiel #13
0
def sushi_part(time, server, sender, channel, message):
	""" message can be empty """
	tab = main_window.find_tab (server, channel)
	nick = parse_from(sender)[0]

	if not tab:
		# ignore this cause it could be this tab was
		# closed recently
		return

	if tab.parent.get_nick() == nick:
		# we parted
		tab.set_joined(False)
		main_window.update_divider()

	else:
		tab.nicklist.remove_nick(nick)

	msg = format_message("actions", "part",
		{"nick": nick,
		 "channel": channel,
		 "reason": message},
		own = (tab.parent.get_nick() == nick),
		highlight = False)
	msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)
Beispiel #14
0
def sushi_quit(time, server, sender, message):
    """ message can be empty """
    server_tab = main_window.find_server(server)

    if not server_tab:
        print_error("No server tab for server '%s'." % (server))
        return

    nick = parse_from(sender)[0]

    msg = format_message("actions",
                         "quit", {
                             "nick": nick,
                             "reason": message
                         },
                         own=(nick == server_tab.get_nick()),
                         highlight=False)
    msg.markup_cb = color_nick_markup_cb

    if nick == server_tab.get_nick():
        # we quit
        server_tab.set_connected(False)

        for child in server_tab.children:
            print_tab(child, msg)

    else:
        for tab in server_tab.children:
            if type(tab) == tabs.Channel and tab.nicklist.has_nick(nick):
                tab.nicklist.remove_nick(nick)
                print_tab(tab, msg)
            elif (type(tab) == tabs.Query
                  and tab.name.lower() == nick.lower()):
                print_tab(tab, msg)
Beispiel #15
0
def sushi_banlist(time, server, channel, mask, who, when):
    """ who can be empty (""), when can be empty (0).
		mask == "" and who == "" and when == -1 => EOL
	"""
    self = helper.code.init_function_attrs(sushi_banlist, first_run=True)

    if "" in (mask, who) and when == -1:
        # EOBL
        self.first_run = True

        msg = format_message("informative",
                             "banlist_end", {"channel": channel},
                             own=False,
                             highlight=False)

        print_tab(self.tab, msg)
    elif self.started:
        # Listing just started

        self.first_run = False

        self.tab = main_window.find_channel_tab(server, channel)

        if not self.tab:
            # SHOULD NOT HAPPEN (banlist only in active channels)
            return

        msg = format_message("informative",
                             "banlist_begin", {"channel": channel},
                             own=False,
                             highlight=False)

        print_tab(self.tab, msg)
    else:
        # Banlist item

        msg = format_message("informative",
                             "banlist_begin", {
                                 "who": who,
                                 "mask": mask,
                                 "when": when
                             },
                             own=False,
                             highlight=False)

        print_tab(self.tab, msg)
Beispiel #16
0
def sushi_nick(time, server, old, new):
    """ old == "" => new == current nick """
    stab = main_window.find_server(server)

    if not stab:
        print_error("missing stab '%s'" % server)
        return

    if not old or old == stab.get_nick():
        stab.set_nick(new)

        if main_window.current_tab in tabs.tree_to_list([stab]):
            main_window.update_divider()

        msg = format_message("actions",
                             "nick", {
                                 "nick": old,
                                 "new_nick": new
                             },
                             own=True,
                             highlight=False)

        current_server_tab_print(server, msg)

    else:
        # print status message in channel tab
        old = connection.parse_from(old)[0]
        new = connection.parse_from(new)[0]

        msg = format_message("actions",
                             "nick", {
                                 "nick": old,
                                 "new_nick": new
                             },
                             own=False,
                             highlight=False)

        msg.markup_cb = color_nick_markup_cb
        msg.markup_cb_kwargs = {"values": ["nick", "new_nick"]}

        for tab in stab.children:
            if type(tab) == tabs.Channel and tab.nicklist.has_nick(old):
                tab.nicklist.rename_nick(old, new)
                print_tab(tab, msg)
Beispiel #17
0
def sushi_banlist(time, server, channel, mask, who, when):
	""" who can be empty (""), when can be empty (0).
		mask == "" and who == "" and when == -1 => EOL
	"""
	self = helper.code.init_function_attrs(sushi_banlist, first_run=True)

	if "" in (mask,who) and when == -1:
		# EOBL
		self.first_run = True

		msg = format_message("informative", "banlist_end",
			{"channel": channel},
			own = False,
			highlight = False)

		print_tab(self.tab, msg)
	elif self.started:
		# Listing just started

		self.first_run = False

		self.tab = main_window.find_channel_tab(server,channel)

		if not self.tab:
			# SHOULD NOT HAPPEN (banlist only in active channels)
			return

		msg = format_message("informative", "banlist_begin",
			{"channel": channel},
			own = False,
			highlight = False)

		print_tab(self.tab, msg)
	else:
		# Banlist item

		msg = format_message("informative", "banlist_begin",
			{"who": who,
			 "mask": mask,
			 "when": when},
			own = False,
			highlight = False)

		print_tab(self.tab, msg)
Beispiel #18
0
 def update_messages(self):
     try:
         response = requests.get(f'{self.url}messages',
                                 params={'after': self.after})
     except:
         return
     messages = response.json()['messages']
     for message in messages:
         self.add_text(format_message(message))
         self.after = message['time']
Beispiel #19
0
def sushi_nick(time, server, old, new):
	""" old == "" => new == current nick """
	stab = main_window.find_server(server)

	if not stab:
		print_error("missing stab '%s'" % server)
		return

	if not old or old == stab.get_nick():
		stab.set_nick(new)

		if main_window.current_tab in tabs.tree_to_list([stab]):
			main_window.update_divider()

		msg = format_message("actions", "nick",
			{"nick": old,
			 "new_nick": new},
			own = True,
			highlight = False)

		current_server_tab_print(server, msg)

	else:
		# print status message in channel tab
		old = connection.parse_from(old)[0]
		new = connection.parse_from(new)[0]

		msg = format_message("actions", "nick",
			{"nick": old,
			 "new_nick": new},
			own = False,
			highlight = False)

		msg.markup_cb = color_nick_markup_cb
		msg.markup_cb_kwargs = {"values":["nick","new_nick"]}

		for tab in stab.children:
			if type(tab) == tabs.Channel and tab.nicklist.has_nick(old):
				tab.nicklist.rename_nick(old,new)
				print_tab(tab, msg)
Beispiel #20
0
def sushi_names(time, server, channel, nicks, prefixes, _call_count = {"n":0}):
	""" len(nicks) == 0 => EOL """
	# TODO: colorize

	tab = find_channel_tab(server, channel)

	if not tab:
		return

	if _call_count["n"] == 0:
		msg = format_message("informative", "names_begin",
			{"channel": channel})
		print_tab(tab, msg)

	if len(nicks) != 0:
		max_width = 7
		width = 0
		msg = ""
		for nick in nicks:
			tab.nicklist.add_nick(nick)

			prefix = prefixes[width]
			msg += prefix+nick+" "

			if (width+1) % max_width == 0 or (width+1) == len(nicks):
				msg = msg[:-1]
				msg = format_message("informative", "names_item",
					{"row": msg})
				print_tab(tab, msg)
				msg = ""

			width += 1

		_call_count["n"] += 1

	else:
		msg = format_message("informative", "names_end", {})
		print_tab(tab, msg)
		_call_count["n"] = 0
Beispiel #21
0
def sushi_names(time, server, channel, nicks, prefixes, _call_count={"n": 0}):
    """ len(nicks) == 0 => EOL """
    # TODO: colorize

    tab = find_channel_tab(server, channel)

    if not tab:
        return

    if _call_count["n"] == 0:
        msg = format_message("informative", "names_begin",
                             {"channel": channel})
        print_tab(tab, msg)

    if len(nicks) != 0:
        max_width = 7
        width = 0
        msg = ""
        for nick in nicks:
            tab.nicklist.add_nick(nick)

            prefix = prefixes[width]
            msg += prefix + nick + " "

            if (width + 1) % max_width == 0 or (width + 1) == len(nicks):
                msg = msg[:-1]
                msg = format_message("informative", "names_item", {"row": msg})
                print_tab(tab, msg)
                msg = ""

            width += 1

        _call_count["n"] += 1

    else:
        msg = format_message("informative", "names_end", {})
        print_tab(tab, msg)
        _call_count["n"] = 0
Beispiel #22
0
def sushi_action(time, server, sender, target, message):
	nick = parse_from(sender)[0]
	tab = find_target_tab(server, target, nick)

	if not tab:
		return

	msg = format_message("messages", "action",
		{"nick": nick,
		 "message": message},
		own = (tab.parent.get_nick() == nick),
		highlight = (nick != tab.parent.get_nick()) and is_highlighted(server, message))

	print_tab(tab, msg)
Beispiel #23
0
def sushi_invite(time, server, sender, channel, who):
	""" sender can be empty """
	sender_name = parse_from(sender)[0]

	msg = format_message("actions", "invite",
		{"nick": sender_name,
		 "who": who,
		 "channel": channel},
		own = (sender_name == main_window.find_server(server).get_nick()),
		highlight = (who == sender_name))

	msg.markup_cb = color_nick_markup_cb

	current_server_tab_print(server, msg)
Beispiel #24
0
def sushi_mode(time, server, sender, target, mode, param):
	""" sender can be empty, param can be empty """
	if sender == "":
		# mode listing
		msg = format_message("actions", "mode_list",
			{"target": target, "mode": mode},
			own = (target == main_window.find_server(server).get_nick()),
			highlight = False)
		current_server_tab_print(server, msg)

	else:
		nick = parse_from(sender)[0]
		msg = format_message("actions", "mode",
			{"nick": nick,
			 "mode": mode,
			 "param": param and " "+param or "",
			 "target": target},
			own = (nick == main_window.find_server(server).get_nick()),
			highlight = (target == main_window.find_server(server).get_nick()))
		msg.markup_cb = color_nick_markup_cb

		tab = main_window.find_tab(server, target)
		print_tab(tab, msg)
Beispiel #25
0
def sushi_invite(time, server, sender, channel, who):
    """ sender can be empty """
    sender_name = parse_from(sender)[0]

    msg = format_message(
        "actions",
        "invite", {
            "nick": sender_name,
            "who": who,
            "channel": channel
        },
        own=(sender_name == main_window.find_server(server).get_nick()),
        highlight=(who == sender_name))

    msg.markup_cb = color_nick_markup_cb

    current_server_tab_print(server, msg)
Beispiel #26
0
def sushi_action(time, server, sender, target, message):
    nick = parse_from(sender)[0]
    tab = find_target_tab(server, target, nick)

    if not tab:
        return

    msg = format_message("messages",
                         "action", {
                             "nick": nick,
                             "message": message
                         },
                         own=(tab.parent.get_nick() == nick),
                         highlight=(nick != tab.parent.get_nick())
                         and is_highlighted(server, message))

    print_tab(tab, msg)
Beispiel #27
0
def sushi_message(time, server, sender, target, message):
	nick = parse_from(sender)[0]
	tab = find_target_tab(server, target, nick)

	if not tab:
		return

	msg = format_message("messages", "message",
		{"message": message,
		 "nick": nick,
		 "prefix": sushi.user_channel_prefix(server, target, nick)},
		own = (nick == tab.parent.get_nick()),
		highlight = (nick != tab.parent.get_nick())
					and is_highlighted(server, message))

	msg.markup_cb = color_nick_markup_cb

	print_tab(tab, msg)
Beispiel #28
0
def sushi_notice(time, server, sender, target, message):
	own_nick = main_window.find_server(server).get_nick()
	nick = parse_from(sender)[0]

	msg = format_message("messages", "notice",
		{"nick": nick,
		 "target": target,
		 "message": message},
		own = (nick == own_nick),
		highlight = is_highlighted(server, message))

	msg.markup_cb = color_nick_markup_cb

	if target[0] in sushi.support_chantypes(server):
		tab = find_target_tab(server, target)
		if not tab:
			current_server_tab_print(server, msg)
	else:
		current_server_tab_print(server, msg)
Beispiel #29
0
def sushi_message(time, server, sender, target, message):
    nick = parse_from(sender)[0]
    tab = find_target_tab(server, target, nick)

    if not tab:
        return

    msg = format_message(
        "messages",
        "message", {
            "message": message,
            "nick": nick,
            "prefix": sushi.user_channel_prefix(server, target, nick)
        },
        own=(nick == tab.parent.get_nick()),
        highlight=(nick != tab.parent.get_nick())
        and is_highlighted(server, message))

    msg.markup_cb = color_nick_markup_cb

    print_tab(tab, msg)
Beispiel #30
0
def sushi_notice(time, server, sender, target, message):
    own_nick = main_window.find_server(server).get_nick()
    nick = parse_from(sender)[0]

    msg = format_message("messages",
                         "notice", {
                             "nick": nick,
                             "target": target,
                             "message": message
                         },
                         own=(nick == own_nick),
                         highlight=is_highlighted(server, message))

    msg.markup_cb = color_nick_markup_cb

    if target[0] in sushi.support_chantypes(server):
        tab = find_target_tab(server, target)
        if not tab:
            current_server_tab_print(server, msg)
    else:
        current_server_tab_print(server, msg)
import requests
import time
from messages import format_message

after = time.time() - 24 * 60 * 60
while True:

    response = requests.get('http://127.0.0.1:5000/messages', params = {'after': after})
    messages = response.json()['messages']
    for message in messages:
        print(format_message(message))
        after = message['time']
    time.sleep(1)
Beispiel #32
0
def sushi_oper(time, server):
	msg = format_message("actions", "oper",
		{"nick": main_window.find_server(server).get_nick()},
		own = True,
		highlight = False)
	current_server_tab_print(server, msg)