Added rename tracking
This commit is contained in:
parent
5ffec27336
commit
139849abb9
3
app.py
3
app.py
|
@ -5,7 +5,8 @@ from bot import Bot
|
|||
bot = Bot("127.0.0.1", 6667, "BabiliBot|py", ["#bots"])
|
||||
|
||||
def processor(name, source, response):
|
||||
bot.send_message(source, "Got response")
|
||||
#bot.send_message(source, "Got response")
|
||||
print(name, source, response)
|
||||
|
||||
if __name__ == "__main__":
|
||||
bot.start(processor, "settings.json")
|
|
@ -9,6 +9,7 @@ class Bot:
|
|||
self.botnick = botnick
|
||||
self.channels = channels
|
||||
self.running = True
|
||||
self.users = dict()
|
||||
|
||||
self.recv_size = 2048
|
||||
|
||||
|
@ -33,6 +34,14 @@ class Bot:
|
|||
message = message.strip("\n\r")
|
||||
print(message)
|
||||
|
||||
user_list = "= {} :".format(chan)
|
||||
raw_users = message.split(user_list)[1].split(" \r\n")[0].split(" ")
|
||||
prefix_filter = lambda u: u[1:] if "~" in u or "@" in u else u
|
||||
users = list(filter(prefix_filter, raw_users))
|
||||
for user in users:
|
||||
if user not in self.users:
|
||||
self.users[user] = dict()
|
||||
|
||||
def ping(self, message):
|
||||
response = message.split("PING :")[1]
|
||||
self.send("PONG :{0}", response)
|
||||
|
@ -43,6 +52,14 @@ class Bot:
|
|||
source, response = after.split(" :", 1)
|
||||
return name, source, response
|
||||
|
||||
def track_rename(self, message):
|
||||
# :aewens|otg!aewensotg@tilde.team NICK aewens|otg2
|
||||
before, new_name = message.split("NICK ", 1)
|
||||
name = before.split("!", 1)[0][1:]
|
||||
user = self.users[name]
|
||||
del self.users[name]
|
||||
self.users[new_name] = user
|
||||
|
||||
def load_settings(self, location):
|
||||
with open(location, "r") as f:
|
||||
self.settings = json.loads(f.read())
|
||||
|
@ -84,15 +101,13 @@ class Bot:
|
|||
|
||||
while self.running:
|
||||
message = self.ircsock.recv(self.recv_size).decode("UTF-8")
|
||||
message = message.strip('\n\r')
|
||||
message = message.strip("\n\r")
|
||||
print(message)
|
||||
|
||||
if "PRIVMSG" in message:
|
||||
name, source, response = self.parse(message)
|
||||
callback(name, source, response)
|
||||
if "PING :" in message:
|
||||
self.ping(message)
|
||||
|
||||
|
||||
|
||||
# = #channel :
|
||||
elif "NICK " in message:
|
||||
self.track_rename(message)
|
||||
elif "PRIVMSG" in message:
|
||||
name, source, response = self.parse(message)
|
||||
callback(name, source, response)
|
Loading…
Reference in New Issue