From 181633e610a5879c88bb3e216a0576958ced91aa Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sat, 24 Sep 2022 09:33:00 +0300 Subject: [PATCH] add irc bot --- ~/Python/README.md | 4 ++++ ~/Python/irc-bot.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 ~/Python/README.md create mode 100755 ~/Python/irc-bot.py diff --git a/~/Python/README.md b/~/Python/README.md new file mode 100644 index 0000000..7698fb8 --- /dev/null +++ b/~/Python/README.md @@ -0,0 +1,4 @@ +# Python + +## Stuff +- [`irc-bot.py`](irc-bot.py) - Простой IRC бот на Python 3 diff --git a/~/Python/irc-bot.py b/~/Python/irc-bot.py new file mode 100755 index 0000000..3d14cd0 --- /dev/null +++ b/~/Python/irc-bot.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import socket +import time + +server = 'iiiypuk.me' +channel = '#admin' +botnick = 'porteus' + +irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +print('Connecting to: ' + server) + +irc.connect((server, 6667)) +irc.send(str.encode('USER ' + botnick + ' localhost localhost :This is a bot!\n')) +irc.send(str.encode('NICK ' + botnick + '\n')) +irc.send(str.encode('JOIN '+ channel +'\n')) + +while True: + text = irc.recv(2040) + print(text) + + if text.find(str.encode('PING')) != -1: + irc.send(str.encode('PONG ' + str(text.split()[1]) + '\r\n')) + + # !time - return current timestamp + if text.find(str.encode('!time')) != -1: + ts = time.time() + irc.send(str.encode('PRIVMSG #admin :{}\r\n'.format(int(ts)))) +