Skip to content

Commit

Permalink
meta-cognition of sorts
Browse files Browse the repository at this point in the history
  • Loading branch information
shardcore committed Apr 23, 2013
1 parent 923b46f commit 17d3fbc
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
3 changes: 2 additions & 1 deletion command_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from commands import regretscommand
from commands import ballcommand
from commands import recapcommand
from commands import commandcommand


# stats
test_command = recapcommand.RecapCommand()
test_command = commandcommand.CommandCommand()
print test_command.generate( "shardcore" )

# ponder
Expand Down
51 changes: 51 additions & 0 deletions commandlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import time
import pkgutil
import datetime
import json
import sys
import logging
import twitterconnector
from hookserver import HookServerMessage, HookServerThread
import queuedthread
import time
from messages import housekeeping, streetnoise
import re
import os
import commands
import urllib2
import urllib

command_list=[]
# import commands
all_commands = []
logging.info( "Loading commands..." )
## load all commands
reload( commands )
for loader, modname, ispkg in pkgutil.iter_modules( commands.__path__, prefix="commands." ):
try:
logging.info( "Scan module: %s" % modname)
module = __import__( modname, fromlist="dummy" )
reload( module )
for klassname in dir( module ):
if "Command" in klassname and "BaseCommand" not in klassname:
logging.info( "...instantiate command: %s" % klassname )
try:
kommandklass = getattr( module, klassname )
kommand = kommandklass()
all_commands.append( kommand )
logging.info( "......instantiated. Triggers are %s" % kommand.command_mappings )
except Exception, e:
logging.info( e )
except Exception, e:
logging.info( e )
global command_list
command_list=all_commands

out='commands: '
for cmd in all_commands:
l=cmd.command_mappings
for c in l:
out=out+c+' '

print out

43 changes: 43 additions & 0 deletions commands/commandcommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# coding=UTF-8

from string import Template
import random
from commandbase import BaseCommand

import pkgutil
import commands

class CommandCommand( BaseCommand ):

def __init__(self):
BaseCommand.__init__( self )
self.command_mappings = [ "command", "cmd", "whut" ]

def generate( self, name ):

command_list=[]
# import commands
all_commands = []

## load all commands
reload( commands )
for loader, modname, ispkg in pkgutil.iter_modules( commands.__path__, prefix="commands." ):


module = __import__( modname, fromlist="dummy" )
reload( module )
for klassname in dir( module ):
if "Command" in klassname and "BaseCommand" not in klassname:


kommandklass = getattr( module, klassname )
kommand = kommandklass()
all_commands.append( kommand )
out='commands: '
for cmd in all_commands:
l=cmd.command_mappings
for c in l:
out=out+c+' '

message_out = out
return "/me %s" % message_out

0 comments on commit 17d3fbc

Please sign in to comment.