There it is.

This commit is contained in:
Bandie Yip Kojote 2016-05-06 21:04:44 +02:00
parent 6a6edb2fd7
commit b17a8dd14d
2 changed files with 138 additions and 1 deletions

116
PagerBot.py Normal file
View File

@ -0,0 +1,116 @@
#!/usr/bin/python
# Author: Bandie Yip Kojote for TTYgap
# License: GNU-GPLv3
# Year: 2016
#
# Software is provided AS IS and so on.
# Host of the IRC server
HOST="irc.example.com"
# TLS port of the IRC server
PORT=6697
# Nick of the bot
NICK="PagerBot"
# Ident of the bot
IDENT="PagerBot"
# Realname of the bot
REALNAME="PagerBot"
# Channel which should be joined
CHAN="#supercoolchan"
# Mail adress you're sending from
FROM="ircbot@example.com"
import sys
import socket
import string
import ssl
import time
import smtplib
def page(receiver, text, user):
number=""
# CONFIGURE YOUR USERS HERE
# if(receiver=="someone"):
# number="1234567"
else:
return "The username you tried to page has no number saved."
to=number+"@ecityruf.de"
message=HOST+":"+user+":"+text
if(len(message)>80):
return "The message \"%s\" is too big. It has to be less than 80 characters.\r\n" % (message)
m = smtplib.SMTP('smtpgw3.emessage.de')
try:
m.sendmail(FROM, to, "FROM: %s\nTO: %s\nSUBJECT: %s" % (FROM, to, message))
except:
e=sys.exc_info()[0]
return "Error: %s" % e
m.quit()
return "Sent."
readbuffer=""
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
ircsock = ssl.wrap_socket(s)
ircsock.send("NICK %s\r\n" % NICK)
ircsock.send("USER %s %s no :%s\r\n" % (IDENT, HOST, REALNAME))
time.sleep(2)
ircsock.send("JOIN %s\r\n" % (CHAN))
print("OK\n")
while 1:
readbuffer=readbuffer+ircsock.recv(1024)
temp=string.split(readbuffer, "\n")
readbuffer=temp.pop( )
pagingtext=""
for line in temp:
line=string.rstrip(line)
line=string.split(line)
if(line[0]=="PING"):
ircsock.send("PONG %s\r\n" % line[1])
if(line[1]=="PRIVMSG" and "#" not in line[2]):
un=string.split(line[0], "!")
un2=string.split(un[0], ":")
usernick=un2[1]
un=None
un2=None
if(line[3] == ":help"):
ircsock.send("PRIVMSG %s This is a bot to use a paging service.\r\n" % usernick)
time.sleep(1)
ircsock.send("PRIVMSG %s Use \"&pager <Username> <Message>\" to page someone.\r\n" % usernick)
elif(line[3] == ":&pager"):
pagingtext=' '.join(line[5:])
print("%s sends to %s \"%s\"\n" % (usernick, line[4], pagingtext))
ircsock.send("PRIVMSG %s %s\r\n" % (usernick, page(line[4], pagingtext, usernick)))
# print(line)

View File

@ -1,2 +1,23 @@
# PagerBot
An IRC bot written in python for paging someone over e*cityruf using mail.
An IRC bot written in python for paging someone over e\*cityruf using mail.
## Requirements
- python
- sys
- socket
- string
- ssl
- time
- smtplib
## Configuration
Look at the code itself.
## Using
Open a query with the bot. Type "help". There you'll see.