From 481dc97789425cb281071f243f4afd292614074c Mon Sep 17 00:00:00 2001 From: GandC Snow Date: Mon, 25 Oct 2021 10:27:58 +0300 Subject: [PATCH] Initial commit --- server.conf | 5 +++++ server.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 server.conf create mode 100644 server.py diff --git a/server.conf b/server.conf new file mode 100644 index 0000000..6500b59 --- /dev/null +++ b/server.conf @@ -0,0 +1,5 @@ +[Global] +IRC_bot_nickname = GandC_LogMon_Bot +IRC_chat_name = #notifications +IRC_host = s1.tomasgl.piv +IRC_port = 6667 diff --git a/server.py b/server.py new file mode 100644 index 0000000..e6803e2 --- /dev/null +++ b/server.py @@ -0,0 +1,42 @@ +## ## +##/dev/udp/ip/port## +from irc import client +from socket import socket, AF_INET, SOCK_DGRAM +from configparser import ConfigParser +from os import chdir, path +from threading import Thread + +host = '10.10.13.1' +port = 7777 +addr = (host,port) + +s = socket(AF_INET, SOCK_DGRAM) # Socket creation +s.bind(addr) # Bind socket to ip + +config = ConfigParser() +chdir(path.dirname(path.abspath(__file__))) +config.read('server.conf') + +def on_connect(connection, event): + connection.mode(config['Global']['IRC_bot_nickname'], '+B') + connection.join(config['Global']['IRC_chat_name']) + +def on_join(connection, event): + connection.privmsg(config['Global']['IRC_chat_name'], 'Bot started') + +def on_disconnect(connection, event): + exit() + +reactor = client.Reactor() +irc = reactor.server() +irc.connect(config['Global']['IRC_host'], int(config['Global']['IRC_port']), config['Global']['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) +s.close()