本文整理汇总了Python中supybot.callbacks.addressed函数的典型用法代码示例。如果您正苦于以下问题:Python addressed函数的具体用法?Python addressed怎么用?Python addressed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addressed函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testAddressedWithMultipleNicks
def testAddressedWithMultipleNicks(self):
msg = ircmsgs.privmsg("#foo", "bar: baz")
self.assertEqual(callbacks.addressed("bar", msg), "baz")
# need to recreate the msg objects since the old ones have already
# been tagged
msg = ircmsgs.privmsg("#foo", "bar: baz")
self.assertEqual(callbacks.addressed("biff", msg, nicks=["bar"]), "baz")
开发者ID:carriercomm,项目名称:Limnoria,代码行数:7,代码来源:test_callbacks.py
示例2: testAddressedWithMultipleNicks
def testAddressedWithMultipleNicks(self):
msg = ircmsgs.privmsg('#foo', 'bar: baz')
self.assertEqual(callbacks.addressed('bar', msg), 'baz')
# need to recreate the msg objects since the old ones have already
# been tagged
msg = ircmsgs.privmsg('#foo', 'bar: baz')
self.assertEqual(callbacks.addressed('biff', msg, nicks=['bar']),
'baz')
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:8,代码来源:test_callbacks.py
示例3: doPrivmsg
def doPrivmsg(self, irc, msg):
channel = msg.args[0].lower()
text = msg.args[1].strip()
# ignore ctcp, action and only messages in a channel.
# if txt.startswith(conf.supybot.reply.whenAddressedBy.chars()):
if ircmsgs.isCtcp(msg) or ircmsgs.isAction(msg) or not irc.isChannel(channel):
return
# on to the text. check if we're ignoring the text matching regex here.
if re.match(self.registryValue('ignoreRegex'), text):
return
# should we strip urls from text?
if self.registryValue('stripUrls'):
text = re.sub(r'(http[^\s]*)', '', text)
# determine probability if addressed or not.
if callbacks.addressed(irc.nick, msg):
text = re.sub('(' + irc.nick + '*?\W+)', '', text, re.IGNORECASE)
probability = self.registryValue('probabilityWhenAddressed', channel)
else:
probability = self.registryValue('probability', channel)
# should we strip nicks from the text?
if self.registryValue('stripNicks'):
removenicks = '|'.join(item + '\W.*?\s' for item in irc.stats.channels[channel].users)
text = re.sub(r'' + removenicks + '', '', text)
# finally, pass to our learn function.
self._learn(irc, channel, text, probability)
开发者ID:carriercomm,项目名称:MegaHAL,代码行数:25,代码来源:plugin.py
示例4: doPrivmsg
def doPrivmsg(self, irc, msg):
if irc.isChannel(msg.args[0]):
channel = plugins.getChannel(msg.args[0])
canSpeak = False
now = time.time()
throttle = self.registryValue('randomSpeaking.throttleTime',
channel)
prob = self.registryValue('randomSpeaking.probability', channel)
delay = self.registryValue('randomSpeaking.maxDelay', channel)
irc = callbacks.SimpleProxy(irc, msg)
if now > self.lastSpoke + throttle:
canSpeak = True
if canSpeak and random.random() < prob:
f = self._markov(channel, irc, prefixNick=False, to=channel,
Random=True)
schedule.addEvent(lambda: self.q.enqueue(f), now + delay)
self.lastSpoke = now + delay
words = self.tokenize(msg)
words.insert(0, '\n')
words.insert(0, '\n')
words.append('\n')
# This shouldn't happen often (CTCP messages being the possible exception)
if not words or len(words) == 3:
return
if self.registryValue('ignoreBotCommands', channel) and \
callbacks.addressed(irc.nick, msg):
return
def doPrivmsg(db):
for (first, second, follower) in utils.seq.window(words, 3):
db.addPair(channel, first, second, follower)
self.q.enqueue(doPrivmsg)
开发者ID:D0MF,项目名称:supybot-plugins,代码行数:31,代码来源:plugin.py
示例5: sendToOthers
def sendToOthers(self, irc, triggerMsg, s):
channel = triggerMsg.args[0]
nick = triggerMsg.nick
for relay in self.relays:
if relay.channelRegex.match(channel) and relay.networkRegex.match(irc.network) and (len(triggerMsg.args[1] < 1 or relay.messageRegex.search(triggerMsg.args[1]))):
if not relay.hasIRC:
self.log.info('LinkRelay: IRC %s not yet scraped.' % relay.targetNetwork)
elif relay.targetIRC.zombie:
self.log.info('LinkRelay: IRC %s appears to be a zombie' % relay.targetNetwork)
elif relay.targetChannel not in relay.targetIRC.state.channels:
self.log.info('LinkRelay: I\'m not in in %s on %s' % (relay.targetChannel, relay.targetNetwork))
else:
# if re.match('\x0314\w+ has quit on \w+ \(.*\)', s):
# pm = False
# else:
# pm = True
# for chan in irc.state.channels:
# if re.match('^%s$' % relay.sourceChannel, chan):
# pm = False
if triggerMsg.args[0] not in irc.state.channels and not re.match('\x0314\w+ has quit on \w+ \(.*\)', s):
# cuts off the end of commands, so that passwords won't be revealed in relayed PM's
if callbacks.addressed(irc.nick, triggerMsg):
s = re.sub('(>\x03 \w+) .*', '\\1 \x0314[truncated]', s)
s = '(via PM) %s' % s
msg = ircmsgs.privmsg(relay.targetChannel, s)
msg.tag('relayedMsg')
relay.targetIRC.sendMsg(msg)
开发者ID:26mansi,项目名称:Supybot-Plugins,代码行数:27,代码来源:plugin.py
示例6: getName
def getName(self, nick, msg, match):
addressed = callbacks.addressed(nick, msg)
name = callbacks.addressed(nick, ircmsgs.IrcMsg(prefix="", args=(msg.args[0], match.group(1)), msg=msg))
if not name:
name = match.group(1)
if not addressed:
if not self.registryValue("allowUnaddressedKarma"):
return ""
if not msg.args[1].startswith(match.group(1)):
return ""
name = match.group(1)
elif addressed:
if not addressed.startswith(name):
return ""
name = name.strip("()")
return name
开发者ID:sylvar,项目名称:supybot-plugins,代码行数:16,代码来源:plugin.py
示例7: doPrivmsg
def doPrivmsg(self, irc, msg):
channel = msg.args[0]
if not irc.isChannel(channel):
return
if self.registryValue('enable', channel):
if callbacks.addressed(irc.nick, msg): #message is direct command
return
actions = []
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("SELECT regexp, action FROM triggers")
results = cursor.fetchall()
if len(results) == 0:
return
for (regexp, action) in results:
for match in re.finditer(regexp, msg.args[1]):
if match is not None:
thisaction = action
self._updateRank(channel, regexp)
for (i, j) in enumerate(match.groups()):
thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction)
actions.append(thisaction)
for action in actions:
self._runCommandFunction(irc, msg, action)
开发者ID:mazaclub,项目名称:mazabot-core,代码行数:25,代码来源:plugin.py
示例8: doPrivmsg
def doPrivmsg(self, irc, msg):
if (irc.isChannel(msg.args[0])):
channel = plugins.getChannel(msg.args[0])
canSpeak = False
now = time.time()
throttle = self.registryValue('randomSpeaking.throttleTime', channel)
prob = self.registryValue('randomSpeaking.probability', channel)
delay = self.registryValue('randomSpeaking.maxDelay', channel)
irc = callbacks.SimpleProxy(irc, msg)
if now > self.lastSpoke + throttle:
canSpeak = True
if canSpeak and random.random() < prob:
#f = self._markov(channel, irc, prefixNick=False, to=channel, Random=True)
reply = self.db.buildReply(channel, None)
if (reply is None):
return
irc.reply(reply, prefixNick=False, to=channel)
#self._markov(channel, irc, prefixNick=False, to=channel, Random=True)
#schedule.addEvent(lambda: self.q.enqueue(f), now+delay)
self.lastSpoke = now+delay
words = self.tokenize(msg)
if not words or len(words) == 3:
return
if (self.registryValue('ignoreBotCommands', channel) and callbacks.addressed(irc.nick, msg)):
return
self.db.addPair(channel, None, words[0])
self.db.addPair(channel, words[-1], None)
for (first, second) in utils.seq.window(words, 2):
self.db.addPair(channel, first, second)
开发者ID:tdfischer,项目名称:supybot-ArtificialIntelligence,代码行数:29,代码来源:plugin.py
示例9: titleSnarfer
def titleSnarfer(self, irc, msg, match):
channel = msg.args[0]
if not irc.isChannel(channel):
return
if callbacks.addressed(irc.nick, msg):
return
if self.registryValue('titleSnarfer', channel):
url = match.group(0)
if not self._checkURLWhitelist(url):
return
r = self.registryValue('nonSnarfingRegexp', channel)
if r and r.search(url):
self.log.debug('Not titleSnarfing %q.', url)
return
r = self.getTitle(irc, url, False)
if not r:
return
(target, title) = r
if title:
domain = utils.web.getDomain(target
if self.registryValue('snarferShowTargetDomain', channel)
else url)
prefix = self.registryValue('snarferPrefix', channel)
s = "%s %s" % (prefix, title)
if self.registryValue('snarferShowDomain', channel):
s += format(_(' (at %s)'), domain)
irc.reply(s, prefixNick=False)
if self.registryValue('snarfMultipleUrls', channel):
# FIXME: hack
msg.tag('repliedTo', False)
开发者ID:ProgVal,项目名称:Limnoria,代码行数:30,代码来源:plugin.py
示例10: doPrivmsg
def doPrivmsg(self, irc, msg):
if callbacks.addressed(irc.nick, msg): #message is not direct command
return
channel = msg.args[0]
if not self.registryValue('correct.enable', channel):
return
if not hasattr(self, '_re'):
threading.Thread(target=self.fetch_dict).start()
return
occurences = self._re.findall(msg.args[1])
if not occurences:
return
unique_occurences = []
occurences_set = set()
for occurence in occurences:
if not occurence in self._dict and \
occurence.endswith('s') and occurence[0:-1] in self._dict:
occurence = occurence[0:-1]
if occurence not in occurences_set:
unique_occurences.append(occurence)
occurences_set.add(occurence)
irc.reply(format('Utilise %L plutôt que %L.',
['« %s »' % self._dict[x] for x in unique_occurences],
['« %s »' % x for x in unique_occurences])
.replace(' and ', ' et ')) # fix i18n
开发者ID:yregaieg,项目名称:Supybot-plugins,代码行数:25,代码来源:plugin.py
示例11: doPrivmsg
def doPrivmsg(self, irc, msg):
if not world.testing and \
msg.args[0] not in ('#limnoria', '#limnoria-bots'):
return
if callbacks.addressed(irc.nick, msg):
return
# Internal
match = self._addressed.match(msg.args[1])
if match is None:
prefix = ''
else:
prefix = match.group(1) + ': '
def reply(string):
irc.reply(prefix + string, prefixNick=False)
# Factoids
matches = self._factoid.findall(msg.args[1])
for name in matches:
arg = None
match = self._dynamicFactoid.match(name)
if match is not None:
name = match.group('name')
arg = match.group('arg')
name = name.lower()
if arg is None:
if name in staticFactoids:
reply(staticFactoids[name])
else:
if name in dynamicFactoids:
reply(dynamicFactoids[name] % arg)
开发者ID:GLolol,项目名称:ProgVal-Supybot-plugins,代码行数:31,代码来源:plugin.py
示例12: doPrivmsg
def doPrivmsg(self, irc, msg):
self.addIRC(irc)
channel = msg.args[0]
s = msg.args[1]
s, args = self.getPrivmsgData(channel, msg.nick, s,
self.registryValue('color', channel))
ignoreNicks = [ircutils.toLower(item) for item in \
self.registryValue('nickstoIgnore.nicks', msg.args[0])]
if self.registryValue('nickstoIgnore.affectPrivmsgs', msg.args[0]) \
== 1 and ircutils.toLower(msg.nick) in ignoreNicks:
#self.log.debug('LinkRelay: %s in nickstoIgnore...' % ircutils.toLower(msg.nick))
#self.log.debug('LinkRelay: List of ignored nicks: %s' % ignoreNicks)
return
elif channel not in irc.state.channels: # in private
# cuts off the end of commands, so that passwords
# won't be revealed in relayed PM's
if callbacks.addressed(irc.nick, msg):
if self.registryValue('color', channel):
color = '\x03' + self.registryValue('colors.truncated',
channel)
match = '(>\017 \w+) .*'
else:
color = ''
match = '(> \w+) .*'
s = re.sub(match, '\\1 %s[%s]' % (color, _('truncated')), s)
s = '(via PM) %s' % s
self.sendToOthers(irc, channel, s, args, isPrivmsg=True)
开发者ID:liam-middlebrook,项目名称:SupyPlugins,代码行数:27,代码来源:plugin.py
示例13: doPrivmsg
def doPrivmsg(self, irc, msg):
if not world.testing and msg.args[0] not in ("#BMN"):
return
if callbacks.addressed(irc.nick, msg):
return
# Internal
match = self._addressed.match(msg.args[1])
if match is None:
prefix = ""
else:
prefix = match.group(1) + ": "
def reply(string):
irc.reply(prefix + string, prefixNick=False)
# Factoids
matches = self._factoid.findall(msg.args[1])
for name in matches:
arg = None
match = self._dynamicFactoid.match(name)
if match is not None:
name = match.group("name")
arg = match.group("arg")
name = name.lower()
if arg is None:
if name in staticFactoids:
reply(staticFactoids[name])
else:
if name in dynamicFactoids:
reply(dynamicFactoids[name] % arg)
开发者ID:Brilliant-Minds,项目名称:Limnoria-Plugins,代码行数:31,代码来源:plugin.py
示例14: doPrivmsg
def doPrivmsg(self, irc, msg):
if not conf.supybot.defaultIgnore(): # Only do this when defaultIgnore is set
return
if chr(1) in msg.args[1]:
return
try:
user = ircdb.users.getUser(msg.prefix)
if user.checkHostmask(msg.prefix):
return
except:
pass
text = callbacks.addressed(irc.nick, msg)
cmd = ''
if not text or text != "login":
if msg.args[1]:
if ircutils.isChannel(msg.args[0]):
if msg.args[1][0] == '@':
cmd = msg.args[1][1:]
else:
if msg.args[1][0] == '@':
cmd = msg.args[1][1:]
else:
cmd = msg.args[1]
if cmd != "login":
return
else:
return
self.log.info("IRCLogin: Calling login for %s" % msg.prefix)
self._callCommand(["login"], irc, msg, [])
开发者ID:bnrubin,项目名称:IRCLogin,代码行数:30,代码来源:plugin.py
示例15: doPrivmsg
def doPrivmsg(self, irc, msg):
if callbacks.addressed(irc.nick, msg): #message is direct command
return
(channel, text) = msg.args
if ircmsgs.isAction(msg):
text = ircmsgs.unAction(msg)
learn = self.registryValue('learn', channel)
reply = self.registryValue('reply', channel)
replyOnMention = self.registryValue('replyOnMention', channel)
replyWhenSpokenTo = self.registryValue('replyWhenSpokenTo', channel)
mention = irc.nick.lower() in text.lower()
spokenTo = msg.args[1].lower().startswith('%s: ' % irc.nick.lower())
if replyWhenSpokenTo and spokenTo:
reply = 100
text = text.replace('%s: ' % irc.nick, '')
text = text.replace('%s: ' % irc.nick.lower(), '')
if replyOnMention and mention:
if not replyWhenSpokenTo and spokenTo:
reply = 0
else:
reply = 100
if randint(0, 99) < reply:
self.reply(irc, msg, text)
if learn:
self.learn(irc, msg, text)
开发者ID:ddack,项目名称:Supybot-plugins,代码行数:32,代码来源:plugin.py
示例16: doPrivmsg
def doPrivmsg(self, irc, msg):
assert self is irc.callbacks[0], \
'Owner isn\'t first callback: %r' % irc.callbacks
if ircmsgs.isCtcp(msg):
return
s = callbacks.addressed(irc.nick, msg)
if s:
ignored = ircdb.checkIgnored(msg.prefix)
if ignored:
self.log.info('Ignoring command from %s.', msg.prefix)
return
maximum = conf.supybot.abuse.flood.command.maximum()
self.commands.enqueue(msg)
if conf.supybot.abuse.flood.command() \
and self.commands.len(msg) > maximum \
and not ircdb.checkCapability(msg.prefix, 'trusted'):
punishment = conf.supybot.abuse.flood.command.punishment()
banmask = ircutils.banmask(msg.prefix)
self.log.info('Ignoring %s for %s seconds due to an apparent '
'command flood.', banmask, punishment)
ircdb.ignores.add(banmask, time.time() + punishment)
irc.reply('You\'ve given me %s commands within the last '
'minute; I\'m now ignoring you for %s.' %
(maximum,
utils.timeElapsed(punishment, seconds=False)))
return
try:
tokens = callbacks.tokenize(s, channel=msg.args[0])
self.Proxy(irc, msg, tokens)
except SyntaxError, e:
irc.queueMsg(callbacks.error(msg, str(e)))
开发者ID:boamaod,项目名称:Limnoria,代码行数:31,代码来源:plugin.py
示例17: doPrivmsg
def doPrivmsg(self, irc, msg):
channel = msg.args[0]
if not irc.isChannel(channel):
return
if self.registryValue('enable', channel):
if callbacks.addressed(irc.nick, msg): #message is direct command
return
actions = []
results = []
for channel in (channel, 'global'):
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("SELECT regexp, action FROM triggers")
# Fetch results and prepend channel name or 'global'. This
# prevents duplicating the following lines.
results.extend(map(lambda x: (channel,)+x, cursor.fetchall()))
if len(results) == 0:
return
for (channel, regexp, action) in results:
for match in re.finditer(regexp, msg.args[1]):
if match is not None:
thisaction = action
self._updateRank(channel, regexp)
for (i, j) in enumerate(match.groups()):
thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction)
actions.append(thisaction)
for action in actions:
self._runCommandFunction(irc, msg, action)
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:29,代码来源:plugin.py
示例18: doPrivmsg
def doPrivmsg(self, irc, msg):
if irc.isChannel(msg.args[0]):
speakChan = msg.args[0]
dbChan = plugins.getChannel(speakChan)
canSpeak = False
now = time.time()
throttle = self.registryValue('randomSpeaking.throttleTime',
speakChan)
prob = self.registryValue('randomSpeaking.probability', speakChan)
delay = self.registryValue('randomSpeaking.maxDelay', speakChan)
if now > self.lastSpoke + throttle:
canSpeak = True
if canSpeak and random.random() < prob:
f = self._markov(speakChan, irc, prefixNick=False,
to=speakChan, Random=True)
schedule.addEvent(lambda: self.q.enqueue(f), now + delay)
self.lastSpoke = now + delay
words = self.tokenize(msg)
# This shouldn't happen often (CTCP messages being the possible
# exception)
if not words:
return
if self.registryValue('ignoreBotCommands', speakChan) and \
callbacks.addressed(irc.nick, msg):
return
words.insert(0, None)
words.insert(0, None)
words.append(None)
def doPrivmsg(db):
for (first, second, follower) in utils.seq.window(words, 3):
db.addPair(dbChan, first, second, follower,
isFirst=(first is None and second is None),
isLast=(follower is None))
self.q.enqueue(doPrivmsg)
开发者ID:GlitterCakes,项目名称:PoohBot,代码行数:34,代码来源:plugin.py
示例19: titleSnarfer
def titleSnarfer(self, irc, msg, match):
channel = msg.args[0]
if not irc.isChannel(channel):
return
if callbacks.addressed(irc.nick, msg):
return
if self.registryValue('titleSnarfer', channel):
url = match.group(0)
r = self.registryValue('nonSnarfingRegexp', channel)
if r and r.search(url):
self.log.debug('Not titleSnarfing %q.', url)
return
try:
size = conf.supybot.protocols.http.peekSize()
text = utils.web.getUrl(url, size=size)
except utils.web.Error, e:
self.log.info('Couldn\'t snarf title of %u: %s.', url, e)
return
parser = Title()
try:
parser.feed(text)
except HTMLParser.HTMLParseError:
self.log.debug('Encountered a problem parsing %u. Title may '
'already be set, though', url)
if parser.title:
domain = utils.web.getDomain(url)
title = utils.web.htmlToText(parser.title.strip())
s = format('Title: %s (at %s)', title, domain)
irc.reply(s, prefixNick=False)
开发者ID:nanotube,项目名称:supybot_fixes,代码行数:29,代码来源:plugin.py
示例20: testAddressedReplyWhenNotAddressed
def testAddressedReplyWhenNotAddressed(self):
msg1 = ircmsgs.privmsg('#foo', '@bar')
msg2 = ircmsgs.privmsg('#foo', 'bar')
self.assertEqual(callbacks.addressed('blah', msg1), 'bar')
self.assertEqual(callbacks.addressed('blah', msg2), '')
try:
original = conf.supybot.reply.whenNotAddressed()
conf.supybot.reply.whenNotAddressed.setValue(True)
# need to recreate the msg objects since the old ones have already
# been tagged
msg1 = ircmsgs.privmsg('#foo', '@bar')
msg2 = ircmsgs.privmsg('#foo', 'bar')
self.assertEqual(callbacks.addressed('blah', msg1), 'bar')
self.assertEqual(callbacks.addressed('blah', msg2), 'bar')
finally:
conf.supybot.reply.whenNotAddressed.setValue(original)
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:16,代码来源:test_callbacks.py
注:本文中的supybot.callbacks.addressed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论