48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
## ##
|
|
##/dev/udp/ip/port##
|
|
from irc import client, connection
|
|
from socket import socket, AF_INET, SOCK_DGRAM
|
|
|
|
#from os import chdir, path
|
|
from threading import Thread
|
|
|
|
host = '10.10.18.3'
|
|
port = 7747
|
|
addr = (host,port)
|
|
|
|
irc_host = 's1.tomasgl.piv'
|
|
irc_port = 6667
|
|
irc_chat_name = '#notifications'
|
|
irc_bot_nickname = 'GandC_LogMon_Bot'
|
|
|
|
s = socket(AF_INET, SOCK_DGRAM) # Socket creation
|
|
s.bind(addr) # Bind socket to ip
|
|
|
|
|
|
#chdir(path.dirname(path.abspath(__file__)))
|
|
|
|
def on_connect(connection, event):
|
|
connection.mode(irc_bot_nickname, '+B')
|
|
connection.join(irc_chat_name)
|
|
|
|
def on_join(connection, event):
|
|
connection.privmsg(irc_chat_name, 'Bot started')
|
|
|
|
def on_disconnect(connection, event):
|
|
exit()
|
|
|
|
reactor = client.Reactor()
|
|
irc = reactor.server()
|
|
irc.connect(irc_host, irc_port, irc_bot_nickname)
|
|
irc.add_global_handler("welcome", on_connect)
|
|
irc.add_global_handler("join", on_join)
|
|
irc.add_global_handler('disconnect', on_disconnect)
|
|
Thread(target=reactor.process_forever).start()
|
|
|
|
while True:
|
|
message, addr = s.recvfrom(1024) # receive message
|
|
print('client addr: ', addr)
|
|
print('info: ', message)
|
|
irc.connection.privmsg(irc_chat_name, message)
|
|
s.close()
|