diff options
Diffstat (limited to 'wmd')
| -rw-r--r-- | wmd/actions/google.py | 2 | ||||
| -rw-r--r-- | wmd/irc.py | 31 |
2 files changed, 28 insertions, 5 deletions
diff --git a/wmd/actions/google.py b/wmd/actions/google.py index 07e2398..d00e651 100644 --- a/wmd/actions/google.py +++ b/wmd/actions/google.py | |||
| @@ -2,7 +2,7 @@ __author__ = 'jason@zzq.org' | |||
| 2 | __version__ = 1.0 | 2 | __version__ = 1.0 |
| 3 | 3 | ||
| 4 | import urllib2 | 4 | import urllib2 |
| 5 | import simplejson | 5 | import json as simplejson |
| 6 | 6 | ||
| 7 | from wmd.actions import Action | 7 | from wmd.actions import Action |
| 8 | 8 | ||
| @@ -3,17 +3,21 @@ import socket | |||
| 3 | from wmd import parser | 3 | from wmd import parser |
| 4 | 4 | ||
| 5 | import settings | 5 | import settings |
| 6 | import pprint | ||
| 6 | 7 | ||
| 7 | class IRC(object): | 8 | class IRC(object): |
| 8 | 9 | ||
| 9 | def __init__(self, server=None, nick=None, name=None, port=6667): | 10 | def __init__(self, server=None, nick=None, name=None, password=None, |
| 11 | port=6667): | ||
| 10 | """ | 12 | """ |
| 11 | IRC connection library that needs at least server, nick and name | 13 | IRC connection library that needs at least server, nick and name |
| 12 | """ | 14 | """ |
| 15 | self.irc = None | ||
| 13 | self.server = server | 16 | self.server = server |
| 14 | self.nick = nick | 17 | self.nick = nick |
| 15 | self.name = name | 18 | self.name = name |
| 16 | self.port = port | 19 | self.port = port |
| 20 | self.password = password | ||
| 17 | 21 | ||
| 18 | # the structure | 22 | # the structure |
| 19 | # TODO: Refactor | 23 | # TODO: Refactor |
| @@ -27,11 +31,29 @@ class IRC(object): | |||
| 27 | """ | 31 | """ |
| 28 | Connects to the irc server. | 32 | Connects to the irc server. |
| 29 | """ | 33 | """ |
| 34 | self.log("Connecting to %s %s" % (self.server, self.port)) | ||
| 30 | self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 35 | self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 36 | using_ssl = False | ||
| 37 | if str(self.port).startswith("+"): | ||
| 38 | using_ssl = True | ||
| 39 | import ssl | ||
| 40 | self.log("Connecting via SSL") | ||
| 41 | self.irc = ssl.wrap_socket(self.irc, | ||
| 42 | ca_certs="certs/GeoTrust_Primary_Certification_Authority_-_G2.pem", | ||
| 43 | ssl_version=ssl.PROTOCOL_TLSv1 | ||
| 44 | ) | ||
| 45 | self.port = int(self.port[1:]) | ||
| 46 | |||
| 31 | self.irc.connect((self.server, self.port)) | 47 | self.irc.connect((self.server, self.port)) |
| 32 | self.log(self.irc.recv(4096)) | 48 | |
| 33 | self.irc.send('NICK ' + self.nick + '\r\n') | 49 | |
| 34 | self.irc.send('USER ' + self.name + ' 8 * :Warmachine\r\n') | 50 | self.rawsend('NICK ' + self.nick + '\r\n') |
| 51 | self.rawsend('USER ' + self.name + ' 8 * :Warmachine\r\n') | ||
| 52 | |||
| 53 | if self.password: | ||
| 54 | self.rawsend('PASS %s\r\n' % (self.password)) | ||
| 55 | |||
| 56 | self.rawsend('\r\n') | ||
| 35 | 57 | ||
| 36 | def join(self, chan): | 58 | def join(self, chan): |
| 37 | """ | 59 | """ |
| @@ -55,6 +77,7 @@ class IRC(object): | |||
| 55 | """ | 77 | """ |
| 56 | Sends commands straight to the irc server. | 78 | Sends commands straight to the irc server. |
| 57 | """ | 79 | """ |
| 80 | self.log(command) | ||
| 58 | self.irc.send(command + '\r\n') | 81 | self.irc.send(command + '\r\n') |
| 59 | 82 | ||
| 60 | def load_actions(self): | 83 | def load_actions(self): |