From e2d43ece40911da7e24f343dfdae51e38aebd2f6 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 23 Apr 2014 15:21:11 -0600 Subject: updated google plugin to use the new json module --- settings.py | 2 +- warmachine | 11 ++++++++--- wmd/actions/google.py | 2 +- wmd/irc.py | 31 +++++++++++++++++++++++++++---- 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' NICKSERV_PASSWORD ='' SERVER = 'irc.freenode.org' -PORT = 6667 +PORT = "+6667" IDENT = 'warmachine' PASSWORD = os.environ['PASSWORD'] diff --git a/warmachine b/warmachine index e4a461a..8ff3a82 100755 --- a/warmachine +++ b/warmachine @@ -9,8 +9,11 @@ if __name__ == '__main__': c = connection.cursor() # check to see if a table exists - is_installed = bool(c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='warmachine_settings'").fetchone()) - print is_installed + is_installed = bool(c.execute("SELECT name FROM sqlite_master WHERE " + "type='table' AND name='warmachine_settings'" + ).fetchone() + ) + if not is_installed: c.execute("""CREATE TABLE warmachine_settings ( key text, @@ -28,8 +31,10 @@ if __name__ == '__main__': ); """) - i = IRC(settings.SERVER, settings.NICKNAME, settings.IDENT, settings.PORT) + i = IRC(settings.SERVER, settings.NICKNAME, settings.IDENT, + settings.PASSWORD, settings.PORT,) i.connect() + import time; time.sleep(10) for channel in settings.CHANNELS: i.join(channel) 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' __version__ = 1.0 import urllib2 -import simplejson +import json as simplejson from wmd.actions import Action 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 from wmd import parser import settings +import pprint class IRC(object): - def __init__(self, server=None, nick=None, name=None, port=6667): + def __init__(self, server=None, nick=None, name=None, password=None, + port=6667): """ IRC connection library that needs at least server, nick and name """ + self.irc = None self.server = server self.nick = nick self.name = name self.port = port + self.password = password # the structure # TODO: Refactor @@ -27,11 +31,29 @@ class IRC(object): """ Connects to the irc server. """ + self.log("Connecting to %s %s" % (self.server, self.port)) self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + using_ssl = False + if str(self.port).startswith("+"): + using_ssl = True + import ssl + self.log("Connecting via SSL") + self.irc = ssl.wrap_socket(self.irc, + ca_certs="certs/GeoTrust_Primary_Certification_Authority_-_G2.pem", + ssl_version=ssl.PROTOCOL_TLSv1 + ) + self.port = int(self.port[1:]) + self.irc.connect((self.server, self.port)) - self.log(self.irc.recv(4096)) - self.irc.send('NICK ' + self.nick + '\r\n') - self.irc.send('USER ' + self.name + ' 8 * :Warmachine\r\n') + + + self.rawsend('NICK ' + self.nick + '\r\n') + self.rawsend('USER ' + self.name + ' 8 * :Warmachine\r\n') + + if self.password: + self.rawsend('PASS %s\r\n' % (self.password)) + + self.rawsend('\r\n') def join(self, chan): """ @@ -55,6 +77,7 @@ class IRC(object): """ Sends commands straight to the irc server. """ + self.log(command) self.irc.send(command + '\r\n') def load_actions(self): -- cgit v1.2.1