bridge_with_irc: Relay msg instead of forge msg on IRC -> Zulip.
This commit is contained in:
parent
a5bc4b716c
commit
9be5ec33b3
|
@ -3,12 +3,6 @@ import irc.strings
|
||||||
from irc.client import ip_numstr_to_quad, ip_quad_to_numstr, Event, ServerConnection
|
from irc.client import ip_numstr_to_quad, ip_quad_to_numstr, Event, ServerConnection
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
IRC_DOMAIN = "irc.example.com"
|
|
||||||
|
|
||||||
def zulip_sender(sender_string):
|
|
||||||
# type: (str) -> str
|
|
||||||
nick = sender_string.split("!")[0]
|
|
||||||
return nick + "@" + IRC_DOMAIN
|
|
||||||
|
|
||||||
class IRCBot(irc.bot.SingleServerIRCBot):
|
class IRCBot(irc.bot.SingleServerIRCBot):
|
||||||
def __init__(self, zulip_client, stream, channel, nickname, server, port=6667):
|
def __init__(self, zulip_client, stream, channel, nickname, server, port=6667):
|
||||||
|
@ -17,6 +11,12 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
||||||
self.channel = channel # type: irc.bot.Channel
|
self.channel = channel # type: irc.bot.Channel
|
||||||
self.zulip_client = zulip_client
|
self.zulip_client = zulip_client
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
|
self.IRC_DOMAIN = server
|
||||||
|
|
||||||
|
def zulip_sender(self, sender_string):
|
||||||
|
# type: (str) -> str
|
||||||
|
nick = sender_string.split("!")[0]
|
||||||
|
return nick + "@" + self.IRC_DOMAIN
|
||||||
|
|
||||||
def on_nicknameinuse(self, c, e):
|
def on_nicknameinuse(self, c, e):
|
||||||
# type: (ServerConnection, Event) -> None
|
# type: (ServerConnection, Event) -> None
|
||||||
|
@ -48,8 +48,8 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
||||||
def on_privmsg(self, c, e):
|
def on_privmsg(self, c, e):
|
||||||
# type: (ServerConnection, Event) -> None
|
# type: (ServerConnection, Event) -> None
|
||||||
content = e.arguments[0]
|
content = e.arguments[0]
|
||||||
sender = zulip_sender(e.source)
|
sender = self.zulip_sender(e.source)
|
||||||
if sender.endswith("_zulip@" + IRC_DOMAIN):
|
if sender.endswith("_zulip@" + self.IRC_DOMAIN):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Forward the PM to Zulip
|
# Forward the PM to Zulip
|
||||||
|
@ -64,18 +64,17 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
||||||
# type: (ServerConnection, Event) -> None
|
# type: (ServerConnection, Event) -> None
|
||||||
content = e.arguments[0]
|
content = e.arguments[0]
|
||||||
stream = self.stream
|
stream = self.stream
|
||||||
sender = zulip_sender(e.source)
|
sender = self.zulip_sender(e.source)
|
||||||
if sender.endswith("_zulip@" + IRC_DOMAIN):
|
if sender.endswith("_zulip@" + self.IRC_DOMAIN):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Forward the stream message to Zulip
|
# Forward the stream message to Zulip
|
||||||
print(self.zulip_client.send_message({
|
print(self.zulip_client.send_message({
|
||||||
"forged": "yes",
|
|
||||||
"sender": sender,
|
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
"to": stream,
|
"to": stream,
|
||||||
"subject": "IRC",
|
"subject": "IRC",
|
||||||
"content": content,
|
"content": content,
|
||||||
|
"content": "**{0}**: {1}".format(sender, content),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
def on_dccmsg(self, c, e):
|
def on_dccmsg(self, c, e):
|
||||||
|
|
Loading…
Reference in a new issue