本文整理汇总了Python中twisted.words.protocols.irc.IRCClient类的典型用法代码示例。如果您正苦于以下问题:Python IRCClient类的具体用法?Python IRCClient怎么用?Python IRCClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IRCClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: irc_ERR_NICKNAMEINUSE
def irc_ERR_NICKNAMEINUSE(self, prefix, params):
"""
Called when we try to register or change to a nickname that is already
taken.
"""
IRCClient.irc_ERR_NICKNAMEINUSE(self, prefix, params)
self._fire_event(irc.on_err_nick_in_use, prefix=prefix, params=params)
示例2: msg
def msg(self, user, message, length=None):
"""
Send a message to a user or channel.
The message will be split into multiple commands to the server if:
- The message contains any newline characters
- Any span between newline characters is longer than the given
line-length.
@type user: Destination, Hostmask or str
@param user: The user or channel to send a notice to.
@type message: str
@param message: The contents of the notice to send.
@type length: int
@param length: Maximum number of octets to send in a single command, including the IRC protocol framing.
If None is given then IRCClient._safeMaximumLineLength is used to determine a value.
"""
if isinstance(user, Destination):
self._log.debug('Implicitly converting Destination to raw format for message delivery: %s --> %s',
repr(user), user.raw)
user = user.raw
if isinstance(user, Hostmask):
self._log.debug('Implicitly converting Hostmask to nick format for message delivery: %s --> %s',
repr(user), user.nick)
user = user.nick
self._log.debug('Delivering message to %s : %s', user, (message[:35] + '..') if len(message) > 35 else message)
IRCClient.msg(self, user, message.encode('utf-8'), length)
示例3: msg
def msg(self, user, message, length=None):
"""
Send a message to a channel, enforces message encoding
"""
encoded_message = unicode(message).encode("ascii", "ignore")
log.msg("Sending %r to %r" % (encoded_message, user))
IRCClient.msg(self, user, encoded_message, length)
示例4: connectionLost
def connectionLost(self, reason):
for channel in self.factory.channels:
self.left(channel)
loggirc2('Connection lost because: %s.' % reason)
self.log("[disconnected at %s]" % time.asctime(time.localtime(time.time())))
self.logger[config.BOTNAME].close()
IRCClient.connectionLost(self, reason)
示例5: connectionMade
def connectionMade(self):
"""This function assumes that the factory was added to this
object by the calling script. It may be more desirable to
implement this as an argument to the __init__"""
self.nickname = self.factory.nickname
self.password = self.factory.password
IRCClient.connectionMade(self)
示例6: kickedFrom
def kickedFrom(self, channel, kicker, message):
"""Handler for kicks. Will join the channel back after 10 seconds."""
self.notice(kicker, "That was mean, I'm just a bot you know");
reactor.callLater(10, self.join, channel)
self.chans.remove(channel);
# Twisted still uses old-style classes, 10 years later. Sigh.
IRCClient.kickedFrom(self, channel, kicker, message)
示例7: _reallySendLine
def _reallySendLine(self, line):
if line.lower().startswith("privmsg") and not line.lower().startswith("privmsg nickserv"):
# FUCK YOU ELITE_SOBA AND ARNAVION
prefix, seperator, text = line.partition(":")
fuckyou = choice([u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u"\u200B", u".kb Elite_Soba ", u".kb Arnavion "])
line = (u"{}{}{}{}".format(prefix, seperator, fuckyou, text.decode("utf8"))).encode("utf8")
IRCClient._reallySendLine(self, line)
示例8: irc_NOTICE
def irc_NOTICE(self, prefix, params):
"""
Called when the bot has received a notice from a user directed to it or a channel.
"""
IRCClient.irc_NOTICE(self, prefix, params)
user = prefix
channel = params[0]
message = params[-1]
示例9: leave
def leave(self, channel):
if channel not in self.channels:
return
del self.channels[channel]
self.config.set("channels", self.channels.keys())
IRCClient.leave(self, channel.encode("utf8"))
nick = normalize(self.nickname)
self.dispatch("left", channel, nick)
示例10: connectionMade
def connectionMade(self):
IRCClient.connectionMade(self)
for chan in self.getChannels():
filename = getLogFilename(self.factory.server, chan)
logger = MessageLogger(filename)
self.loggers.update({chan: logger})
logger.log("[connected at %s]" %
time.asctime(time.localtime(time.time())))
示例11: connectionMade
def connectionMade(self):
with open(strftime('%B %d, %Y.txt'), 'a') as log1:
log1.write(strftime('\
[%H:%M:%S] ') + 'Connecting...' + '\n')
print strftime('[%H:%M:%S on %B %d, %Y] ') + 'Connecting...'
self.sendLine('CAP REQ :sasl')
self.deferred = Deferred()
IRCClient.connectionMade(self)
示例12: connectionLost
def connectionLost(self, reason):
log.warn(
"Disconnected from %s (%s:%s): %s" % (self.servername, self.factory.hostname, self.factory.port, reason)
)
IRCClient.connectionLost(self, reason)
try:
self.l.stop() # All done now.
except AssertionError:
pass # We never managed to connect in the first place!
示例13: connectionMade
def connectionMade(self):
IRCClient.connectionMade(self)
self._names = {}
self._banlist = {}
self._exceptlist = {}
self._invitelist = {}
# TODO: I think this should be on "signedOn()" just in case part of the signon is causing instant disconnect
# reset connection factory delay:
self.factory.resetDelay()
示例14: irc_PART
def irc_PART(self, prefix, params):
"""
Called when a user leaves a channel.
"""
IRCClient.irc_PART(self, prefix, params)
nick, ident, host = process_hostmask(prefix)
channel = params[0]
if nick == self.nickname:
self.state.channels.remove(channel)
示例15: signedOn
def signedOn(self):
"""Called when bot has succesfully signed on to server."""
print "[Signed on]"
IRCClient.signedOn(self)
for chan in self.channels:
print 'Joining %s' % chan
self.join(chan)
log.msg("[%s] Connection made and all channels joined, registering." % self.label)
relayer.register(self)