Moved ircbot code into bot folder

This commit is contained in:
aewens 2018-09-04 20:52:04 -04:00
parent 40fd6625dc
commit 5ffec27336
2 changed files with 12 additions and 10 deletions

8
app.py Normal file → Executable file
View File

@ -4,12 +4,8 @@ from bot import Bot
bot = Bot("127.0.0.1", 6667, "BabiliBot|py", ["#bots"])
def processor(message):
if "PRIVMSG" in message:
name, source, response = parse(message)
bot.send_message(source, "Got response")
if "PING :" in message:
ping(message)
def processor(name, source, response):
bot.send_message(source, "Got response")
if __name__ == "__main__":
bot.start(processor, "settings.json")

View File

@ -17,11 +17,11 @@ class Bot:
print("DEBUG: ", response)
self.ircsock.send(response.encode())
def send_message(target, message, *args):
def send_message(self, target, message, *args):
msg = message.format(*args)
response = "PRIVMSG {0} :{1}".format(target, msg) + "\n"
print("DEBUG: ", response)
ircsock.send(response.encode())
self.ircsock.send(response.encode())
def join(self, chan, confirmed=False):
self.send("JOIN {}", chan)
@ -71,7 +71,7 @@ class Bot:
registered = True
if not registered and "choose a different nick" in message:
self.send_message("NickServ", "IDENTIFY {}", password)
if not confirmed and "Your account will expire" i message:
if not confirmed and "Your account will expire" in message:
self.send_message("NickServ", "CONFIRM {}", self.confirm)
confirmed = True
@ -87,6 +87,12 @@ class Bot:
message = message.strip('\n\r')
print(message)
callback()
if "PRIVMSG" in message:
name, source, response = self.parse(message)
callback(name, source, response)
if "PING :" in message:
self.ping(message)
# = #channel :