added tracking certain words in words.py and fixed/changed a couple of things to allow it to work.
This commit is contained in:
parent
27c0de701c
commit
afec1deb5c
3 changed files with 20 additions and 3 deletions
|
@ -19,6 +19,7 @@ class Bot(object):
|
||||||
nickname, username, realname, connect=False):
|
nickname, username, realname, connect=False):
|
||||||
new_server = IRCServer.Server(id, hostname, port, password,
|
new_server = IRCServer.Server(id, hostname, port, password,
|
||||||
ipv4, tls, nickname, username, realname, self)
|
ipv4, tls, nickname, username, realname, self)
|
||||||
|
self.events.on("new").on("server").call(server=new_server)
|
||||||
self.servers[new_server.fileno()] = new_server
|
self.servers[new_server.fileno()] = new_server
|
||||||
if connect:
|
if connect:
|
||||||
self.connect(new_server)
|
self.connect(new_server)
|
||||||
|
|
|
@ -3,19 +3,35 @@
|
||||||
class Module(object):
|
class Module(object):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
bot.events.on("new").on("server").hook(self.new_server)
|
||||||
bot.events.on("received").on("message").on("channel"
|
bot.events.on("received").on("message").on("channel"
|
||||||
).hook(self.channel_message)
|
).hook(self.channel_message)
|
||||||
bot.events.on("received").on("command").on("words"
|
bot.events.on("received").on("command").on("words"
|
||||||
).hook(self.words, channel_only=True)
|
).hook(self.words, channel_only=True)
|
||||||
|
|
||||||
|
def new_server(self, event):
|
||||||
|
event["server"].tracked_words = set([])
|
||||||
|
settings = event["server"].find_settings("word-%")
|
||||||
|
for word, _ in settings:
|
||||||
|
word = word.split("word-", 1)[1]
|
||||||
|
event["server"].tracked_words.add(word)
|
||||||
|
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
word_count = len(list(filter(None, event["message_split"
|
words = list(filter(None, event["message_split"]))
|
||||||
])))
|
word_count = len(words)
|
||||||
words = event["user"].get_setting("words", {})
|
words = event["user"].get_setting("words", {})
|
||||||
if not event["channel"].name in words:
|
if not event["channel"].name in words:
|
||||||
words[event["channel"].name] = 0
|
words[event["channel"].name] = 0
|
||||||
words[event["channel"].name] += word_count
|
words[event["channel"].name] += word_count
|
||||||
event["user"].set_setting("words", words)
|
event["user"].set_setting("words", words)
|
||||||
|
for word in words:
|
||||||
|
if word.lower() in event["server"].tracked_words:
|
||||||
|
setting = "word-%s" % word
|
||||||
|
tracked_word = event["server"].get_setting(setting, {})
|
||||||
|
if not event["user"].name in tracked_word:
|
||||||
|
tracked_word[event["user"].name] = 0
|
||||||
|
tracked_word[event["user"].name] += 1
|
||||||
|
event["server"].set_setting(setting, tracked_word)
|
||||||
|
|
||||||
def words(self, event):
|
def words(self, event):
|
||||||
if event["args_split"]:
|
if event["args_split"]:
|
||||||
|
|
2
start.py
2
start.py
|
@ -20,12 +20,12 @@ database = Database.Database(bot, args.database)
|
||||||
config_object = Config.Config(bot, args.config)
|
config_object = Config.Config(bot, args.config)
|
||||||
bot.database = database
|
bot.database = database
|
||||||
bot.config_object = config_object
|
bot.config_object = config_object
|
||||||
|
bot.modules.load_modules()
|
||||||
|
|
||||||
servers = database.get_servers()
|
servers = database.get_servers()
|
||||||
for server in servers:
|
for server in servers:
|
||||||
bot.add_server(*server)
|
bot.add_server(*server)
|
||||||
if len(bot.servers):
|
if len(bot.servers):
|
||||||
bot.modules.load_modules()
|
|
||||||
bot.events.on("boot").on("done").call()
|
bot.events.on("boot").on("done").call()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
bot.connect_all()
|
bot.connect_all()
|
||||||
|
|
Loading…
Reference in a new issue