Skip to content

Commit 4ec5102

Browse files
author
none
committedJan 28, 2013
enter
0 parents  commit 4ec5102

File tree

569 files changed

+101593
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

569 files changed

+101593
-0
lines changed
 

‎README

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Welcome to JSONBOT
2+
==================
3+
4+
JSONBOT is a remote event-driven framework for building bots that talk JSON to
5+
each other over XMPP.
6+
7+
This distribution provides bots built on this framework for console, IRC,
8+
XMPP and WWW on the shell.
9+
10+
the jsb pakage contains the following programs:
11+
12+
* jsb - console version of jsb
13+
* jsb-makecert - create keys and certifictes for web console SSL
14+
* jsb-init - create data directory and config examples, default ~/.jsb
15+
* jsb-irc - IRC version of jsb
16+
* jsb-fleet - mix IRC and XMPP bots
17+
* jsb-sed - sed a whole directory
18+
* jsb-stop - stop a running bot
19+
* jsb-tornado - a shell web server based on tornado
20+
* jsb-udp - send udp packets to the bot that will relay the data
21+
* jsb-udpdirect - a stand alone udp program, copy & edit
22+
* jsb-xmpp - XMPP version of jsb
23+
24+
note: JSONBOT is in BETA stage right now and still subject to change of protocols and API.
25+
26+
see http://jsonbot.googlecode.com.
27+
see https://jsonbot.org for documentation on the bot.
28+
29+
license
30+
~~~~~~~
31+
32+
JSONBOT is free code (MIT) and can be cloned where needed.
33+
34+
contact the developer
35+
~~~~~~~~~~~~~~~~~~~~~
36+
37+
* email: bthate@gmail.com
38+
* jabber/xmpp: bthate@gmail.com
39+
* IRC: botfather on #dunkbots irc.freenode.net
40+
* twitter: http://twitter.com/jsonbot
41+
42+
urls
43+
~~~~
44+
45+
* Source code: http://jsonbot.googlecode.com
46+
* web: http://jsonbot.org:10102 (web)
47+
* jabber: jsonbot@jsonbot.org
48+
49+
running a development version of the bot
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
52+
first checkout the main bot from the mercurial repository
53+
54+
hg clone http://jsonbot.googlecode.com/hg mybot
55+
56+
now you can run the programs in the bin directory with the
57+
./bin/<program> command. try ./bin/jsb for the console app
58+

‎bin/jsb

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env python2.7
2+
#
3+
#
4+
5+
""" Console Bot. """
6+
7+
8+
#import warnings
9+
#warnings.simplefilter("ignore")
10+
11+
## bootstrap
12+
13+
import os, sys
14+
sys.path.insert(0, os.getcwd())
15+
sys.path.insert(0, os.getcwd() + os.sep + "..")
16+
17+
18+
## etc
19+
20+
from jsb.version import getversion
21+
22+
from jsb.utils.log import setloglevel
23+
24+
## command line parsing
25+
26+
from optparse import OptionParser
27+
parser = OptionParser(usage='usage: %prog [options] <appid>', version='%prog ' + getversion())
28+
parser.add_option('-d', '--datadir', type='string', default=False, dest='datadir', help="datadir to use")
29+
parser.add_option('-c', '--channel', type='string', default=False, dest='channel', help="channel to operate on")
30+
parser.add_option('-n', '--name', type='string', default=False, dest='name', help="name of the console bot")
31+
parser.add_option('-l', '--loglevel', type='string', default=False, dest='loglevel', help="logging level")
32+
parser.add_option('', '--nocbs', type='string', default=False, dest='nocbs', help="callback types to exclude from running")
33+
parser.add_option('-f', '--fast', action="store_true", default=False, dest='fast', help="boot fast (dont load myplugs)")
34+
parser.add_option('', '--nocolors', action="store_true", default=False, dest='nocolors', help="enable the use of colors")
35+
parser.add_option('', '--fleet', action="store_true", default=False, dest='fleet', help="start the fleet")
36+
parser.add_option('', '--nourl', action="store_true", default=False, dest='nourl', help="disable geturl functionality")
37+
parser.add_option('', '--lazy', action="store_true", default=False, dest='lazy', help="enable lazy importing")
38+
39+
opts, args = parser.parse_args()
40+
opts.args = args
41+
42+
if not opts.args: print getversion('CONSOLE')
43+
if opts.lazy:
44+
from jsb.contrib import lazyimport
45+
lazyimport.install()
46+
if opts.datadir:
47+
if not os.path.isdir(opts.datadir): os.mkdir(opts.datadir)
48+
from jsb.lib.datadir import setdatadir
49+
setdatadir(opts.datadir)
50+
51+
## make config from cmndline options
52+
53+
from jsb.utils.log import setloglevel
54+
setloglevel(opts.loglevel or "error", not opts.nocolors)
55+
56+
if opts.nourl:
57+
from jsb.utils.url import url_disable
58+
url_disable()
59+
60+
from jsb.lib.boot import boot
61+
if opts.fast: boot(opts.datadir, fast=True)
62+
else: boot(opts.datadir)
63+
64+
## jsb imports
65+
66+
from jsb.utils.exception import handle_exception
67+
from jsb.utils.generic import waitforqueue, waitevents
68+
from jsb.drivers.console.bot import ConsoleBot
69+
from jsb.lib.config import Config
70+
from jsb.lib.errors import NoOwnerSet, NoSuchCommand
71+
from jsb.lib.commands import cmnds
72+
from jsb.lib.exit import globalshutdown
73+
from jsb.lib.fleet import getfleet
74+
from jsb.lib.threads import start_new_thread
75+
from jsb.lib.datadir import getdatadir
76+
77+
## basic imports
78+
79+
import getpass
80+
import time
81+
import logging
82+
83+
## start the bot
84+
name = opts.name or "default-console"
85+
cfg = Config("fleet" + os.sep + name + os.sep + 'config')
86+
if not cfg.owner: cfg.owner = []
87+
userid = getpass.getuser() + '@' + cfg.uuid
88+
89+
if userid not in cfg.owner: cfg.owner.append(userid) ; cfg.save()
90+
91+
try:
92+
bot = ConsoleBot(cfg, nocbs=opts.nocbs)
93+
except NoOwnerSet:
94+
print "the owner is not set in %s" % cfg.cfile
95+
os._exit(1)
96+
97+
if opts.args:
98+
cmndstring = ";"
99+
for cmnd in opts.args:
100+
if "|" in cmnd: break
101+
cmndstring += u"%s " % unicode(cmnd)
102+
event = bot.make_event(userid, opts.channel or userid, cmndstring.strip(), showall=True)
103+
event.directoutput = True
104+
event.nodispatch = False
105+
try: event.execute(True)
106+
except NoSuchCommand, ex: print "no %s command found." % str(ex).strip()
107+
print ""
108+
try:
109+
sys.stdout.close()
110+
except: pass
111+
os._exit(0)
112+
113+
print "datadir is %s" % getdatadir()
114+
bot.start(False)
115+
if bot.maincfg.dbenable: print "dbtype is %s" % bot.maincfg.dbtype
116+
fleet = getfleet()
117+
fleet.addbot(bot)
118+
119+
if opts.fleet:
120+
bots = fleet.loadall()
121+
logging.error("starting fleet %s" % fleet.list())
122+
start_new_thread(fleet.startall, ())
123+
124+
bot.startshell()
125+
globalshutdown()

0 commit comments

Comments
 (0)
Please sign in to comment.