Code aufge-pep8-pt
This commit is contained in:
parent
321e43dc78
commit
bfacdfc284
94
PagerBot.py
94
PagerBot.py
@ -1,28 +1,28 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# Author: Bandie Yip Kojote for TTYgap
|
# Author: Bandie Yip Kojote for TTYgap
|
||||||
# License: GNU-GPLv3
|
# License: GNU-GPLv3
|
||||||
# Year: 2016
|
# Year: 2016
|
||||||
#
|
#
|
||||||
# Software is provided AS IS and so on.
|
# Software is provided AS IS and so on.
|
||||||
|
|
||||||
|
|
||||||
# Host of the IRC server
|
# Host of the IRC server
|
||||||
HOST="irc.example.com"
|
HOST = "irc.example.com"
|
||||||
# TLS port of the IRC server
|
# TLS port of the IRC server
|
||||||
PORT=6697
|
PORT = 6697
|
||||||
# Nick of the bot
|
# Nick of the bot
|
||||||
NICK="PagerBot"
|
NICK = "PagerBot"
|
||||||
# Ident of the bot
|
# Ident of the bot
|
||||||
IDENT="PagerBot"
|
IDENT = "PagerBot"
|
||||||
# Realname of the bot
|
# Realname of the bot
|
||||||
REALNAME="PagerBot"
|
REALNAME = "PagerBot"
|
||||||
# Channel which should be joined
|
# Channel which should be joined
|
||||||
CHAN="#supercoolchan"
|
CHAN = "#supercoolchan"
|
||||||
|
|
||||||
|
|
||||||
# Mail adress you're sending from
|
# Mail address you're sending from
|
||||||
FROM="ircbot@example.com"
|
FROM = "ircbot@example.com"
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -40,6 +40,7 @@ phonebook = {}
|
|||||||
# phonebook["someone"] = "123456"
|
# phonebook["someone"] = "123456"
|
||||||
# phonebook["someoneelse"] = "7654321"
|
# phonebook["someoneelse"] = "7654321"
|
||||||
|
|
||||||
|
|
||||||
def page(receiver, text, user):
|
def page(receiver, text, user):
|
||||||
|
|
||||||
if receiver in phonebook:
|
if receiver in phonebook:
|
||||||
@ -47,77 +48,72 @@ def page(receiver, text, user):
|
|||||||
else:
|
else:
|
||||||
return "The username you tried to page has no number saved."
|
return "The username you tried to page has no number saved."
|
||||||
|
|
||||||
|
to = number + "@ecityruf.de"
|
||||||
|
message = HOST + ":" + user + ":" + text
|
||||||
|
if(len(message) > 80):
|
||||||
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)
|
return "The message \"%s\" is too big. It has to be less than 80 characters.\r\n" % (message)
|
||||||
m = smtplib.SMTP('smtpgw3.emessage.de')
|
m = smtplib.SMTP('smtpgw3.emessage.de')
|
||||||
try:
|
try:
|
||||||
m.sendmail(FROM, to, "FROM: %s\nTO: %s\nSUBJECT: %s" % (FROM, to, message))
|
m.sendmail(FROM, to, "FROM: %s\nTO: %s\nSUBJECT: %s" %
|
||||||
|
(FROM, to, message))
|
||||||
except:
|
except:
|
||||||
e=sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
return "Error: %s" % e
|
return "Error: %s" % e
|
||||||
m.quit()
|
m.quit()
|
||||||
return "Sent."
|
return "Sent."
|
||||||
|
|
||||||
|
|
||||||
|
readbuffer = ""
|
||||||
|
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
readbuffer=""
|
|
||||||
|
|
||||||
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
s.connect((HOST, PORT))
|
s.connect((HOST, PORT))
|
||||||
ircsock = ssl.wrap_socket(s)
|
ircsock = ssl.wrap_socket(s)
|
||||||
ircsock.send("NICK %s\r\n" % (NICK))
|
ircsock.send("NICK %s\r\n" % (NICK))
|
||||||
ircsock.send("USER %s %s no :%s\r\n" % (IDENT, HOST, REALNAME))
|
ircsock.send("USER %s %s no :%s\r\n" % (IDENT, HOST, REALNAME))
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
ircsock.send("MODE %s +B\r\n" %(NICK))
|
ircsock.send("MODE %s +B\r\n" % (NICK))
|
||||||
ircsock.send("JOIN %s\r\n" % (CHAN))
|
ircsock.send("JOIN %s\r\n" % (CHAN))
|
||||||
print("OK\n")
|
print("OK\n")
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
readbuffer=readbuffer+ircsock.recv(1024)
|
readbuffer = readbuffer + ircsock.recv(1024)
|
||||||
temp=string.split(readbuffer, "\n")
|
temp = string.split(readbuffer, "\n")
|
||||||
readbuffer=temp.pop( )
|
readbuffer = temp.pop()
|
||||||
|
|
||||||
pagingtext=""
|
pagingtext = ""
|
||||||
|
|
||||||
for line in temp:
|
for line in temp:
|
||||||
line=string.rstrip(line)
|
line = string.rstrip(line)
|
||||||
line=string.split(line)
|
line = string.split(line)
|
||||||
|
|
||||||
|
if(line[0] == "PING"):
|
||||||
|
|
||||||
if(line[0]=="PING"):
|
|
||||||
ircsock.send("PONG %s\r\n" % line[1])
|
ircsock.send("PONG %s\r\n" % line[1])
|
||||||
|
|
||||||
if(line[1]=="PRIVMSG"):
|
if(line[1] == "PRIVMSG"):
|
||||||
un=string.split(line[0], "!")
|
un = string.split(line[0], "!")
|
||||||
un2=string.split(un[0], ":")
|
un2 = string.split(un[0], ":")
|
||||||
usernick=un2[1]
|
usernick = un2[1]
|
||||||
|
|
||||||
if("#" in line[2]):
|
if("#" in line[2]):
|
||||||
if(line[3] == ":%s:" % (NICK) or line[3] == ":&pager"):
|
if(line[3] == ":%s:" % (NICK) or line[3] == ":&pager"):
|
||||||
ircsock.send("PRIVMSG %s %s: I only do stuff via query.\r\n" % (line[2], usernick))
|
ircsock.send(
|
||||||
|
"PRIVMSG %s %s: I only do stuff via query.\r\n" % (line[2], usernick))
|
||||||
|
|
||||||
if("#" not in line[2]):
|
if("#" not in line[2]):
|
||||||
if(line[3] == ":help"):
|
if(line[3] == ":help"):
|
||||||
ircsock.send("PRIVMSG %s This is a bot to use a paging service.\r\n" % (usernick))
|
ircsock.send(
|
||||||
|
"PRIVMSG %s This is a bot to use a paging service.\r\n" % (usernick))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ircsock.send("PRIVMSG %s Use \"/msg %s &pager <Username> <Message>\" to page someone.\r\n" % (usernick, NICK))
|
ircsock.send(
|
||||||
|
"PRIVMSG %s Use \"/msg %s &pager <Username> <Message>\" to page someone.\r\n" % (usernick, NICK))
|
||||||
elif(line[3] == ":&pager"):
|
elif(line[3] == ":&pager"):
|
||||||
pagingtext=' '.join(line[5:])
|
pagingtext = ' '.join(line[5:])
|
||||||
print("%s tries to send to %s \"%s\"\n" % (usernick, line[4], pagingtext))
|
print("%s tries to send to %s \"%s\"\n" %
|
||||||
ircsock.send("PRIVMSG %s %s\r\n" % (usernick, page(line[4], pagingtext, usernick)))
|
(usernick, line[4], pagingtext))
|
||||||
|
ircsock.send("PRIVMSG %s %s\r\n" %
|
||||||
|
(usernick, page(line[4], pagingtext, usernick)))
|
||||||
elif(line[3] == ":&phonebook"):
|
elif(line[3] == ":&phonebook"):
|
||||||
ircsock.send("PRIVMSG %s %s\r\n" % (usernick, phonebook.keys()))
|
ircsock.send("PRIVMSG %s %s\r\n" %
|
||||||
|
(usernick, phonebook.keys()))
|
||||||
|
|
||||||
# print(line)
|
# print(line)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user