diff options
| -rw-r--r-- | settings.py | 2 | ||||
| -rwxr-xr-x | warmachine | 11 | ||||
| -rw-r--r-- | wmd/actions/google.py | 2 | ||||
| -rw-r--r-- | wmd/irc.py | 31 |
4 files changed, 37 insertions, 9 deletions
diff --git a/settings.py b/settings.py index bdb1e17..f511ef0 100644 --- a/settings.py +++ b/settings.py | |||
| @@ -8,7 +8,7 @@ NICKNAME = 'warmachine' | |||
| 8 | NICKSERV_PASSWORD ='' | 8 | NICKSERV_PASSWORD ='' |
| 9 | 9 | ||
| 10 | SERVER = 'irc.freenode.org' | 10 | SERVER = 'irc.freenode.org' |
| 11 | PORT = 6667 | 11 | PORT = "+6667" |
| 12 | IDENT = 'warmachine' | 12 | IDENT = 'warmachine' |
| 13 | 13 | ||
| 14 | CHANNELS = ('#warmachine-dev',) | 14 | CHANNELS = ('#warmachine-dev',) |
| @@ -9,8 +9,11 @@ if __name__ == '__main__': | |||
| 9 | c = connection.cursor() | 9 | c = connection.cursor() |
| 10 | 10 | ||
| 11 | # check to see if a table exists | 11 | # check to see if a table exists |
| 12 | is_installed = bool(c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='warmachine_settings'").fetchone()) | 12 | is_installed = bool(c.execute("SELECT name FROM sqlite_master WHERE " |
| 13 | print is_installed | 13 | "type='table' AND name='warmachine_settings'" |
| 14 | ).fetchone() | ||
| 15 | ) | ||
| 16 | |||
| 14 | if not is_installed: | 17 | if not is_installed: |
| 15 | c.execute("""CREATE TABLE warmachine_settings ( | 18 | c.execute("""CREATE TABLE warmachine_settings ( |
| 16 | key text, | 19 | key text, |
| @@ -28,8 +31,10 @@ if __name__ == '__main__': | |||
| 28 | ); | 31 | ); |
| 29 | """) | 32 | """) |
| 30 | 33 | ||
| 31 | i = IRC(settings.SERVER, settings.NICKNAME, settings.IDENT, settings.PORT) | 34 | i = IRC(settings.SERVER, settings.NICKNAME, settings.IDENT, |
| 35 | settings.PASSWORD, settings.PORT,) | ||
| 32 | i.connect() | 36 | i.connect() |
| 37 | import time; time.sleep(10) | ||
| 33 | for channel in settings.CHANNELS: | 38 | for channel in settings.CHANNELS: |
| 34 | i.join(channel) | 39 | i.join(channel) |
| 35 | i() | 40 | i() |
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): |