This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.application import internet, service | |
from twisted.words.protocols import irc | |
from twisted.internet import protocol | |
class Bot(irc.IRCClient): | |
nickname = "SocPuppet" | |
def connectionMade(self): | |
irc.IRCClient.connectionMade(self) | |
print "Connected" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.words.protocols import irc | |
from twisted.internet import protocol, reactor | |
import traceback | |
class Bot(irc.IRCClient): | |
nickname = "SocPuppet" | |
def try_except(self, func, *args): | |
try: | |
return func(*args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Manager(object): | |
def __init__(self): | |
self.triggers = defaultdict(list) # event: [func, ] | |
def register(self, *events): | |
def register_for_event(func): | |
for event in events: | |
self.triggers[event.lower()].append(func) | |
return func |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c = ConfigObj("socuppet.conf") | |
p = PluginManager() | |
f = BotFactory(c, p) | |
if "servers" in c: | |
for name, server in c['servers'].iteritems(): | |
botService = internet.TCPClient(server["host"], 6667, f) | |
botService.startService() | |
reactor.addSystemEventTrigger('before', 'shutdown', botService.stopService) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BotFactory(protocol.ReconnectingClientFactory): | |
protocol = Bot | |
def __init__(self, config, name, state): | |
self.config = config | |
self.name = name | |
self.sharedstate = state | |
self.quitted = False | |
def clientConnectionLost(self, connector, unused_reason): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d = defer.maybeDeferred(func, self, user, channel, msg) | |
d.addErrback(self.printerror) | |
d.addCallback(self.msg, channel) | |
def msg(self, user, message): | |
pass | |
# user ends up having the message, and message the target. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The only requirements are that the process ends with a specific return code (7 in this case) | |
import os | |
import sys | |
import subprocess | |
class main(object): | |
def __init__(self, file, cwd): | |
self.file = os.path.abspath(file) | |
self.cwd = os.path.abspath(cwd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
class User(object): | |
def __init__(self): | |
self.password = "" | |
def set_password(self, raw_password): | |
hash = "pass" # randomly generate this | |
m = hashlib.sha1(raw_password + hash) | |
self.password = "%s$%s" % (m.hexdigest(), hash) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
class Klass(object): | |
def func(self): | |
"""Ohai from Klass.func""" | |
print self.func.__doc__ | |
def Func(): | |
"""Ohai from __main__.Func""" | |
print Func.__doc__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Manager(object): | |
def __init__(self): | |
self.strings = defaultdict(list) # { stringname: [func1, func2, ...], ... } | |
def deco(self, string): | |
def decofunc(func): | |
self.strings[string].append(func) | |
return func |