Start a message by nemubot: is equivalent to talk in private message

This commit is contained in:
nemunaire 2014-08-07 19:13:52 +02:00
parent c15127feb8
commit 99c6a5c271
3 changed files with 13 additions and 11 deletions

21
bot.py
View File

@ -354,6 +354,13 @@ class Bot:
def treat_pre(self, msg, srv): def treat_pre(self, msg, srv):
"""Treat a message before all other treatment""" """Treat a message before all other treatment"""
# Treat all messages starting with 'nemubot:' as distinct commands
if msg.cmd == "PRIVMSG" and msg.content.find("%s:"%srv.nick) == 0:
# Remove the bot name
msg.content = msg.content[len(srv.nick)+1:].strip()
msg.parse_content()
msg.private = True
for h, lvl, store, bot in self.create_cache("all_pre"): for h, lvl, store, bot in self.create_cache("all_pre"):
if h.is_matching(None, server=srv): if h.is_matching(None, server=srv):
h.run(msg, self.create_cache) h.run(msg, self.create_cache)
@ -407,19 +414,12 @@ class Bot:
else: else:
return _ctcp_response(msg.sender, "ERRMSG Unknown or unimplemented CTCP request") return _ctcp_response(msg.sender, "ERRMSG Unknown or unimplemented CTCP request")
# Treat all messages starting with 'nemubot:' as distinct commands
elif msg.content.find("%s:"%srv.nick) == 0:
# Remove the bot name
msg.content = msg.content[len(srv.nick)+1:].strip()
return self.treat_prvmsg_ask(msg, srv)
# Owner commands # Owner commands
elif len(msg.content) > 0 and msg.content[0] == '`' and msg.nick == srv.owner: if len(msg.content) > 1 and msg.content[0] == '`' and msg.nick == srv.owner:
#TODO: owner commands #TODO: owner commands
pass pass
elif len(msg.content) > 0 and msg.content[0] == '!' and len(msg.content) > 1: elif len(msg.content) > 1 and msg.content[0] == '!':
# Remove the ! # Remove the !
msg.cmds[0] = msg.cmds[0][1:] msg.cmds[0] = msg.cmds[0][1:]
@ -450,8 +450,9 @@ class Bot:
else: else:
res = self.treat_answer(msg, srv) res = self.treat_answer(msg, srv)
# Assume the message starts with nemubot: # Assume the message starts with nemubot:
if (res is None or len(res) <= 0) and msg.private: if not res and msg.private:
return self.treat_prvmsg_ask(msg, srv) return self.treat_prvmsg_ask(msg, srv)
return res return res

View File

@ -87,6 +87,7 @@ class MessageConsumer:
msg.server = self.srv.id msg.server = self.srv.id
if msg.cmd == "PRIVMSG": if msg.cmd == "PRIVMSG":
msg.is_owner = (msg.nick == self.srv.owner) msg.is_owner = (msg.nick == self.srv.owner)
msg.private = msg.private or msg.channel == self.srv.nick
res = self.treat_in(context, msg) res = self.treat_in(context, msg)
except: except:
print ("\033[1;31mERROR:\033[0m occurred during the " print ("\033[1;31mERROR:\033[0m occurred during the "

View File

@ -41,7 +41,7 @@ def save():
class Message: class Message:
def __init__ (self, line, timestamp, private = False): def __init__ (self, line, timestamp, private=False):
self.raw = line self.raw = line
self.time = timestamp self.time = timestamp
self.channel = None self.channel = None