summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjason2014-04-23 15:21:11 -0600
committerjason2014-05-28 02:06:08 -0600
commite2d43ece40911da7e24f343dfdae51e38aebd2f6 (patch)
treeea014ed4ee5f14e03965d069e674119bf5d1f0b1
parent126f8a496be0b089e95cbbc357400fc90d6b8571 (diff)
downloadwarmachine-e2d43ece40911da7e24f343dfdae51e38aebd2f6.tar.gz
warmachine-e2d43ece40911da7e24f343dfdae51e38aebd2f6.zip
updated google plugin to use the new json module
-rw-r--r--settings.py2
-rwxr-xr-xwarmachine11
-rw-r--r--wmd/actions/google.py2
-rw-r--r--wmd/irc.py31
4 files changed, 37 insertions, 9 deletions
diff --git a/settings.py b/settings.py
index beda64f..dc423cb 100644
--- a/settings.py
+++ b/settings.py
@@ -9,7 +9,7 @@ NICKNAME = 'warmachine'
9NICKSERV_PASSWORD ='' 9NICKSERV_PASSWORD =''
10 10
11SERVER = 'irc.freenode.org' 11SERVER = 'irc.freenode.org'
12PORT = 6667 12PORT = "+6667"
13IDENT = 'warmachine' 13IDENT = 'warmachine'
14PASSWORD = os.environ['PASSWORD'] 14PASSWORD = os.environ['PASSWORD']
15 15
diff --git a/warmachine b/warmachine
index e4a461a..8ff3a82 100755
--- a/warmachine
+++ b/warmachine
@@ -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
4import urllib2 4import urllib2
5import simplejson 5import json as simplejson
6 6
7from wmd.actions import Action 7from wmd.actions import Action
8 8
diff --git a/wmd/irc.py b/wmd/irc.py
index 68a5384..bce84b2 100644
--- a/wmd/irc.py
+++ b/wmd/irc.py
@@ -3,17 +3,21 @@ import socket
3from wmd import parser 3from wmd import parser
4 4
5import settings 5import settings
6import pprint
6 7
7class IRC(object): 8class 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):