typing: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting assignment type annotations, which require Python 3.6), followed by some manual whitespace adjustment, and two fixes for use-before-define issues: - def set_zulip_client(self, zulipToJabberClient: ZulipToJabberBot) -> None: + def set_zulip_client(self, zulipToJabberClient: 'ZulipToJabberBot') -> None: -def init_from_options(options: Any, client: Optional[str] = None) -> Client: +def init_from_options(options: Any, client: Optional[str] = None) -> 'Client': Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
7c5f73dce9
commit
5428c5f296
42 changed files with 311 additions and 577 deletions
|
@ -9,9 +9,8 @@ from typing import Any, Dict
|
|||
class IRCBot(irc.bot.SingleServerIRCBot):
|
||||
reactor_class = AioReactor
|
||||
|
||||
def __init__(self, zulip_client, stream, topic, channel,
|
||||
nickname, server, nickserv_password='', port=6667):
|
||||
# type: (Any, str, str, irc.bot.Channel, str, str, str, int) -> None
|
||||
def __init__(self, zulip_client: Any, stream: str, topic: str, channel: irc.bot.Channel,
|
||||
nickname: str, server: str, nickserv_password: str = '', port: int = 6667) -> None:
|
||||
self.channel = channel # type: irc.bot.Channel
|
||||
self.zulip_client = zulip_client
|
||||
self.stream = stream
|
||||
|
@ -23,13 +22,11 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
|||
# Initialize IRC bot after proper connection to Zulip server has been confirmed.
|
||||
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
|
||||
|
||||
def zulip_sender(self, sender_string):
|
||||
# type: (str) -> str
|
||||
def zulip_sender(self, sender_string: str) -> str:
|
||||
nick = sender_string.split("!")[0]
|
||||
return nick + "@" + self.IRC_DOMAIN
|
||||
|
||||
def connect(self, *args, **kwargs):
|
||||
# type: (*Any, **Any) -> None
|
||||
def connect(self, *args: Any, **kwargs: Any) -> None:
|
||||
# Taken from
|
||||
# https://github.com/jaraco/irc/blob/master/irc/client_aio.py,
|
||||
# in particular the method of AioSimpleIRCClient
|
||||
|
@ -38,8 +35,7 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
|||
)
|
||||
print("Listening now. Please send an IRC message to verify operation")
|
||||
|
||||
def check_subscription_or_die(self):
|
||||
# type: () -> None
|
||||
def check_subscription_or_die(self) -> None:
|
||||
resp = self.zulip_client.list_subscriptions()
|
||||
if resp["result"] != "success":
|
||||
print("ERROR: %s" % (resp["msg"],))
|
||||
|
@ -49,19 +45,16 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
|||
print("The bot is not yet subscribed to stream '%s'. Please subscribe the bot to the stream first." % (self.stream,))
|
||||
exit(1)
|
||||
|
||||
def on_nicknameinuse(self, c, e):
|
||||
# type: (ServerConnection, Event) -> None
|
||||
def on_nicknameinuse(self, c: ServerConnection, e: Event) -> None:
|
||||
c.nick(c.get_nickname().replace("_zulip", "__zulip"))
|
||||
|
||||
def on_welcome(self, c, e):
|
||||
# type: (ServerConnection, Event) -> None
|
||||
def on_welcome(self, c: ServerConnection, e: Event) -> None:
|
||||
if len(self.nickserv_password) > 0:
|
||||
msg = 'identify %s' % (self.nickserv_password,)
|
||||
c.privmsg('NickServ', msg)
|
||||
c.join(self.channel)
|
||||
|
||||
def forward_to_irc(msg):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
def forward_to_irc(msg: Dict[str, Any]) -> None:
|
||||
not_from_zulip_bot = msg["sender_email"] != self.zulip_client.email
|
||||
if not not_from_zulip_bot:
|
||||
# Do not forward echo
|
||||
|
@ -88,8 +81,7 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
|||
z2i = mp.Process(target=self.zulip_client.call_on_each_message, args=(forward_to_irc,))
|
||||
z2i.start()
|
||||
|
||||
def on_privmsg(self, c, e):
|
||||
# type: (ServerConnection, Event) -> None
|
||||
def on_privmsg(self, c: ServerConnection, e: Event) -> None:
|
||||
content = e.arguments[0]
|
||||
sender = self.zulip_sender(e.source)
|
||||
if sender.endswith("_zulip@" + self.IRC_DOMAIN):
|
||||
|
@ -103,8 +95,7 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
|||
"content": content,
|
||||
}))
|
||||
|
||||
def on_pubmsg(self, c, e):
|
||||
# type: (ServerConnection, Event) -> None
|
||||
def on_pubmsg(self, c: ServerConnection, e: Event) -> None:
|
||||
content = e.arguments[0]
|
||||
sender = self.zulip_sender(e.source)
|
||||
if sender.endswith("_zulip@" + self.IRC_DOMAIN):
|
||||
|
@ -119,12 +110,10 @@ class IRCBot(irc.bot.SingleServerIRCBot):
|
|||
"content": "**{}**: {}".format(sender, content),
|
||||
}))
|
||||
|
||||
def on_dccmsg(self, c, e):
|
||||
# type: (ServerConnection, Event) -> None
|
||||
def on_dccmsg(self, c: ServerConnection, e: Event) -> None:
|
||||
c.privmsg("You said: " + e.arguments[0])
|
||||
|
||||
def on_dccchat(self, c, e):
|
||||
# type: (ServerConnection, Event) -> None
|
||||
def on_dccchat(self, c: ServerConnection, e: Event) -> None:
|
||||
if len(e.arguments) != 2:
|
||||
return
|
||||
args = e.arguments[1].split()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue