Define methods in IRCClient instead of using a decorator
Mypy doesn't like it.
This commit is contained in:
parent
273db4b553
commit
6460eb6804
@ -61,22 +61,7 @@ class TokenBucket(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{self.__class__.__name__}(capacity={self.capacity}, fill rate={self.fill_rate}, tokens={self.tokens})".format(self=self)
|
return "{self.__class__.__name__}(capacity={self.capacity}, fill rate={self.fill_rate}, tokens={self.tokens})".format(self=self)
|
||||||
|
|
||||||
def add_commands(d):
|
class IRCClient:
|
||||||
def dec(cls):
|
|
||||||
for c in d:
|
|
||||||
def func(x):
|
|
||||||
def gen(self, *a):
|
|
||||||
self.send(x.upper(), *a)
|
|
||||||
return gen
|
|
||||||
setattr(cls, c, func(c))
|
|
||||||
return cls
|
|
||||||
return dec
|
|
||||||
@add_commands(("join",
|
|
||||||
"mode",
|
|
||||||
"nick",
|
|
||||||
"who",
|
|
||||||
"cap"))
|
|
||||||
class IRCClient(object):
|
|
||||||
""" IRC Client class. This handles one connection to a server.
|
""" IRC Client class. This handles one connection to a server.
|
||||||
This can be used either with or without IRCApp ( see connect() docs )
|
This can be used either with or without IRCApp ( see connect() docs )
|
||||||
"""
|
"""
|
||||||
@ -188,7 +173,7 @@ class IRCClient(object):
|
|||||||
if not self.blocking:
|
if not self.blocking:
|
||||||
self.socket.setblocking(0)
|
self.socket.setblocking(0)
|
||||||
|
|
||||||
self.cap("LS", "302")
|
self.cap("LS 302")
|
||||||
|
|
||||||
if self.server_pass and (not self.sasl_auth or "{password}" not in self.server_pass):
|
if self.server_pass and (not self.sasl_auth or "{password}" not in self.server_pass):
|
||||||
message = "PASS :{0}".format(self.server_pass).format(
|
message = "PASS :{0}".format(self.server_pass).format(
|
||||||
@ -271,12 +256,22 @@ class IRCClient(object):
|
|||||||
line = line[:maxchars]
|
line = line[:maxchars]
|
||||||
self.send("NOTICE", user, ":{0}".format(line))
|
self.send("NOTICE", user, ":{0}".format(line))
|
||||||
line = extra
|
line = extra
|
||||||
|
def join(self, channel):
|
||||||
|
self.send("JOIN {0}".format(channel))
|
||||||
def quit(self, msg=""):
|
def quit(self, msg=""):
|
||||||
self.send("QUIT :{0}".format(msg))
|
self.send("QUIT :{0}".format(msg))
|
||||||
def part(self, chan, msg=""):
|
def part(self, chan, msg=""):
|
||||||
self.send("PART {0} :{1}".format(chan, msg))
|
self.send("PART {0} :{1}".format(chan, msg))
|
||||||
|
def mode(self, *args):
|
||||||
|
self.send("MODE {0}".format(" ".join(args)))
|
||||||
def kick(self, chan, nick, msg=""):
|
def kick(self, chan, nick, msg=""):
|
||||||
self.send("KICK", chan, nick, ":"+msg)
|
self.send("KICK", chan, nick, ":"+msg)
|
||||||
|
def nick(self, nick):
|
||||||
|
self.send("NICK {0}".format(nick))
|
||||||
|
def who(self, *args):
|
||||||
|
self.send("WHO {0}".format(" ".join(args)))
|
||||||
|
def cap(self, req):
|
||||||
|
self.send("CAP {0}".format(req))
|
||||||
def ns_identify(self, account, passwd, nickserv, command):
|
def ns_identify(self, account, passwd, nickserv, command):
|
||||||
if command:
|
if command:
|
||||||
self.msg(nickserv, command.format(account=account, password=passwd))
|
self.msg(nickserv, command.format(account=account, password=passwd))
|
||||||
|
@ -145,7 +145,7 @@ def connect_callback(cli):
|
|||||||
common_caps = request_caps & supported_caps
|
common_caps = request_caps & supported_caps
|
||||||
|
|
||||||
if common_caps:
|
if common_caps:
|
||||||
cli.cap("REQ", ":{0}".format(" ".join(common_caps)))
|
cli.cap("REQ " ":{0}".format(" ".join(common_caps)))
|
||||||
elif cmd == "ACK":
|
elif cmd == "ACK":
|
||||||
if "sasl" in caps:
|
if "sasl" in caps:
|
||||||
cli.send("AUTHENTICATE PLAIN")
|
cli.send("AUTHENTICATE PLAIN")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user