43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
##pip3 install irc##
|
|
from irc import client, connection
|
|
from socket import socket, AF_INET, SOCK_DGRAM
|
|
from threading import Thread
|
|
|
|
host = '0.0.0.0'
|
|
port = 7747
|
|
addr = (host,port)
|
|
|
|
irc_host = 's1.tomas.gl'
|
|
irc_port = 6667
|
|
irc_chat_name = '#notifications'
|
|
irc_bot_nickname = 'Test_BOT'
|
|
|
|
s = socket(AF_INET, SOCK_DGRAM) # Socket creation
|
|
s.bind(addr) # Bind socket to ip
|
|
|
|
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(1)
|
|
|
|
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)
|
|
while True:
|
|
Thread(target=reactor.process_forever).start()
|
|
|
|
while True:
|
|
message, addr = s.recvfrom(1024) # receive message
|
|
#print('client addr: ', addr)
|
|
#print('info: ', message.decode())
|
|
irc.privmsg(irc_chat_name, message.decode().strip())
|
|
s.close()
|