snipplets.dev/~/Python/irc-bot.py

30 lines
759 B
Python
Raw Normal View History

2022-09-24 09:33:00 +03:00
#!/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:
2023-06-03 23:49:12 +03:00
text = irc.recv(2040)
print(text)
2022-09-24 09:33:00 +03:00
2023-06-03 23:49:12 +03:00
if text.find(str.encode('PING')) != -1:
irc.send(str.encode('PONG ' + str(text.split()[1]) + '\r\n'))
2022-09-24 09:33:00 +03:00
2023-06-03 23:49:12 +03:00
# !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))))
2022-09-24 09:33:00 +03:00