Browse Source

There it is.

master
Bandie Yip Kojote 4 years ago
parent
commit
b17a8dd14d
2 changed files with 138 additions and 1 deletions
  1. 116
    0
      PagerBot.py
  2. 22
    1
      README.md

+ 116
- 0
PagerBot.py View File

@@ -0,0 +1,116 @@
1
+#!/usr/bin/python
2
+
3
+# Author: Bandie Yip Kojote for TTYgap
4
+# License: GNU-GPLv3
5
+# Year: 2016
6
+# 
7
+# Software is provided AS IS and so on.
8
+
9
+
10
+# Host of the IRC server
11
+HOST="irc.example.com"
12
+# TLS port of the IRC server
13
+PORT=6697
14
+# Nick of the bot
15
+NICK="PagerBot"
16
+# Ident of the bot
17
+IDENT="PagerBot"
18
+# Realname of the bot
19
+REALNAME="PagerBot"
20
+# Channel which should be joined
21
+CHAN="#supercoolchan"
22
+
23
+
24
+# Mail adress you're sending from
25
+FROM="ircbot@example.com"
26
+
27
+
28
+import sys
29
+import socket
30
+import string
31
+import ssl
32
+import time
33
+import smtplib
34
+
35
+
36
+
37
+
38
+def page(receiver, text, user):
39
+
40
+    number=""
41
+
42
+
43
+    # CONFIGURE YOUR USERS HERE
44
+
45
+#    if(receiver=="someone"):
46
+#        number="1234567"
47
+
48
+    else:
49
+        return "The username you tried to page has no number saved."
50
+
51
+
52
+
53
+
54
+    to=number+"@ecityruf.de"
55
+    message=HOST+":"+user+":"+text
56
+    if(len(message)>80):
57
+        return "The message \"%s\" is too big. It has to be less than 80 characters.\r\n" % (message)
58
+    m = smtplib.SMTP('smtpgw3.emessage.de')
59
+    try:
60
+        m.sendmail(FROM, to, "FROM: %s\nTO: %s\nSUBJECT: %s" % (FROM, to, message))
61
+    except:
62
+        e=sys.exc_info()[0]
63
+        return "Error: %s" % e
64
+    m.quit()
65
+    return "Sent."
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+readbuffer=""
74
+
75
+s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
76
+s.connect((HOST, PORT))
77
+ircsock = ssl.wrap_socket(s)
78
+ircsock.send("NICK %s\r\n" % NICK)
79
+ircsock.send("USER %s %s no :%s\r\n" % (IDENT, HOST, REALNAME))
80
+time.sleep(2)
81
+ircsock.send("JOIN %s\r\n" % (CHAN))
82
+print("OK\n")
83
+
84
+while 1:
85
+    readbuffer=readbuffer+ircsock.recv(1024)
86
+    temp=string.split(readbuffer, "\n")
87
+    readbuffer=temp.pop( )
88
+
89
+    pagingtext=""
90
+
91
+    for line in temp:
92
+        line=string.rstrip(line)
93
+        line=string.split(line)
94
+
95
+        if(line[0]=="PING"):
96
+            ircsock.send("PONG %s\r\n" % line[1])
97
+        if(line[1]=="PRIVMSG" and "#" not in line[2]):
98
+            un=string.split(line[0], "!")
99
+            un2=string.split(un[0], ":")
100
+            usernick=un2[1]
101
+            un=None
102
+            un2=None
103
+            if(line[3] == ":help"):
104
+                ircsock.send("PRIVMSG %s This is a bot to use a paging service.\r\n" % usernick)
105
+                time.sleep(1)
106
+                ircsock.send("PRIVMSG %s Use \"&pager <Username> <Message>\" to page someone.\r\n" % usernick)
107
+
108
+            elif(line[3] == ":&pager"):
109
+                pagingtext=' '.join(line[5:])
110
+                print("%s sends to %s \"%s\"\n" % (usernick, line[4], pagingtext))
111
+                ircsock.send("PRIVMSG %s %s\r\n" % (usernick, page(line[4], pagingtext, usernick)))
112
+
113
+
114
+#    print(line)
115
+
116
+

+ 22
- 1
README.md View File

@@ -1,2 +1,23 @@
1 1
 # PagerBot
2
-An IRC bot written in python for paging someone over e*cityruf using mail.
2
+An IRC bot written in python for paging someone over e\*cityruf using mail.
3
+
4
+
5
+## Requirements
6
+
7
+- python
8
+- sys
9
+- socket
10
+- string
11
+- ssl
12
+- time
13
+- smtplib
14
+
15
+
16
+## Configuration
17
+
18
+Look at the code itself.
19
+
20
+
21
+## Using
22
+
23
+Open a query with the bot. Type "help". There you'll see.

Loading…
Cancel
Save