Move files around and update references

This commit is contained in:
Vgr E.Barry 2015-03-21 14:29:21 -04:00
parent 5264a2a0da
commit 378334478c
9 changed files with 80 additions and 129 deletions

View File

@ -1,58 +0,0 @@
import argparse
import botconfig
from settings import wolfgame as var
# Todo: Allow game modes to be set via config
# Handle launch parameters
# Argument --debug means start in debug mode
# --verbose means to print a lot of stuff (when not in debug mode)
# --normal means to override the above and use nothing
# Settings can be defined in the config, but launch argumentss override it
debug_mode = False
verbose = False
sabotage = False
normal = False
# Carry over settings from botconfig into settings/wolfgame.py
for setting, value in botconfig.__dict__.items():
if not setting.isupper():
continue # Not a setting
if setting == "DEBUG_MODE":
debug_mode = value
if setting == "VERBOSE_MODE":
verbose = value
if setting == "DEFAULT_MODULE":
sabotage = value
if setting == "NORMAL_MODE":
normal = value
if not setting in var.__dict__.keys():
continue # Don't carry over config-only settings
# If we got that far, it's valid
setattr(var, setting, value)
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true')
parser.add_argument('--sabotage', action='store_true')
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--normal', action='store_true')
args = parser.parse_args()
if args.debug: debug_mode = True
if args.verbose: verbose = True
if args.sabotage: sabotage = True
if args.normal: normal = True
botconfig.DEBUG_MODE = debug_mode if not botconfig.DISABLE_DEBUG_MODE and not normal else False
botconfig.VERBOSE_MODE = verbose if not normal else False
botconfig.DEFAULT_MODULE = "sabotage" if args.sabotage else "wolfgame"
# Initialize Database
var.init_db()

View File

@ -1 +0,0 @@
# PLACEHOLDER, DO NOT DELETE THIS FILE

View File

@ -1,4 +1,57 @@
import argparse
import botconfig
from settings import wolfgame as var
# Todo: Allow game modes to be set via config
# Handle launch parameters
# Argument --debug means start in debug mode
# --verbose means to print a lot of stuff (when not in debug mode)
# --normal means to override the above and use nothing
# Settings can be defined in the config, but launch argumentss override it
debug_mode = False
verbose = False
normal = False
# Carry over settings from botconfig into settings.py
for setting, value in botconfig.__dict__.items():
if not setting.isupper():
continue # Not a setting
if setting == "DEBUG_MODE":
debug_mode = value
if setting == "VERBOSE_MODE":
verbose = value
if setting == "NORMAL_MODE":
normal = value
if not setting in var.__dict__.keys():
continue # Don't carry over config-only settings
# If we got that far, it's valid
setattr(var, setting, value)
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true')
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--normal', action='store_true')
args = parser.parse_args()
if args.debug: debug_mode = True
if args.verbose: verbose = True
if args.normal: normal = True
botconfig.DEBUG_MODE = debug_mode if not botconfig.DISABLE_DEBUG_MODE and not normal else False
botconfig.VERBOSE_MODE = verbose if not normal else False
# Initialize Database
var.init_db()
# Logger
import datetime
import time

View File

@ -11,8 +11,8 @@
from oyoyo.parse import parse_nick
import fnmatch
import botconfig
import settings.wolfgame as var
from tools import logger
import src.settings as var
from src import logger
adminlog = logger(None)

View File

@ -1,15 +1,15 @@
# The bot commands implemented in here are present no matter which module is loaded
import botconfig
from tools import decorators
import tools.moduleloader as ld
from src import decorators
import traceback
from base64 import b64encode
from oyoyo.parse import parse_nick
import imp
from tools import logger
from src import logger
import socket
import settings.wolfgame as var
from src import settings as var
from src import wolfgame
log = logger("errors.log")
alog = logger(None)
@ -37,7 +37,6 @@ def notify_error(cli, chan, target_logger):
def on_privmsg(cli, rawnick, chan, msg, notice = False):
currmod = ld.MODULES[ld.CURRENT_MODULE]
try:
prefixes = getattr(var, "STATUSMSG_PREFIXES")
@ -54,8 +53,8 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
if chan == botconfig.NICK:
chan = parse_nick(rawnick)[0]
if currmod and "" in currmod.COMMANDS.keys():
for fn in currmod.COMMANDS[""]:
if "" in wolfgame.COMMANDS.keys():
for fn in wolfgame.COMMANDS[""]:
try:
fn(cli, rawnick, chan, msg)
except Exception:
@ -65,7 +64,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
notify_error(cli, chan, log)
for x in set(list(COMMANDS.keys()) + (list(currmod.COMMANDS.keys()) if currmod else list())):
for x in set(list(COMMANDS.keys()) + list(wolfgame.COMMANDS.keys())):
if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
break # channel message but no prefix; ignore
if msg.lower().startswith(botconfig.CMD_CHAR+x):
@ -75,7 +74,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
else:
continue
if not h or h[0] == " ":
for fn in COMMANDS.get(x, []) + (currmod.COMMANDS.get(x, []) if currmod else []):
for fn in COMMANDS.get(x, []) + (wolfgame.COMMANDS.get(x, [])):
try:
fn(cli, rawnick, chan, h.lstrip())
except Exception:
@ -84,15 +83,13 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
else:
notify_error(cli, chan, log)
def __unhandled__(cli, prefix, cmd, *args):
currmod = ld.MODULES[ld.CURRENT_MODULE]
if cmd in set(list(HOOKS.keys())+(list(currmod.HOOKS.keys()) if currmod else list())):
def unhandled(cli, prefix, cmd, *args):
if cmd in set(list(HOOKS.keys()) + list(wolfgame.HOOKS.keys())):
largs = list(args)
for i,arg in enumerate(largs):
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
for fn in HOOKS.get(cmd, [])+(currmod.HOOKS.get(cmd, []) if currmod else []):
for fn in HOOKS.get(cmd, []) + wolfgame.HOOKS.get(cmd, []):
try:
fn(cli, prefix, *largs)
except Exception as e:
@ -123,11 +120,8 @@ def connect_callback(cli):
cli.cap("REQ", "extended-join")
cli.cap("REQ", "account-notify")
try:
ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli)
except AttributeError:
pass # no connect_callback for this one
wolfgame.connect_callback(cli)
cli.nick(botconfig.NICK) # very important (for regain/release)
@ -191,15 +185,4 @@ def connect_callback(cli):
def on_ping(cli, prefix, server):
cli.send('PONG', server)
if botconfig.DEBUG_MODE:
@cmd("module", admin_only = True)
def ch_module(cli, nick, chan, rest):
rest = rest.strip()
if rest in ld.MODULES.keys():
ld.CURRENT_MODULE = rest
ld.MODULES[rest].connect_callback(cli)
cli.msg(chan, "Module {0} is now active.".format(rest))
else:
cli.msg(chan, "Module {0} does not exist.".format(rest))
# vim: set expandtab:sw=4:ts=4:

View File

@ -20,10 +20,10 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from oyoyo.parse import parse_nick
import settings.wolfgame as var
import src.settings as var
import botconfig
import traceback
from tools import decorators
from src import decorators
from datetime import datetime, timedelta
import threading
import copy
@ -36,7 +36,7 @@ import math
import random
import subprocess
import signal
from tools import logger
from src import logger
import urllib.request
import sqlite3

View File

@ -1,26 +0,0 @@
import os
import botconfig
from tools import logger
MODULES = {}
for modfile in os.listdir("modules"):
if modfile == "common.py":
continue # no need to load this one
if modfile.startswith("__"):
continue
if not modfile.endswith(".py"):
continue # not a module
if not os.path.isfile("modules/"+modfile):
continue # not a file
modfile = modfile[:-3]
logger(None)("Loading module "+modfile)
MODULES[modfile] = getattr(__import__("modules."+modfile), modfile)
if botconfig.DEFAULT_MODULE in MODULES.keys():
CURRENT_MODULE = botconfig.DEFAULT_MODULE.lower()
else:
CURRENT_MODULE = "wolfgame"

View File

@ -26,15 +26,15 @@ from oyoyo.client import IRCClient
import botconfig
import time
import traceback
import modules.common
import tools
import src
from src import handler
def main():
cli = IRCClient(
{"privmsg": modules.common.on_privmsg,
"notice": lambda a, b, c, d: modules.common.on_privmsg(a, b, c, d, True),
"": modules.common.__unhandled__},
{"privmsg": handler.on_privmsg,
"notice": lambda a, b, c, d: handler.on_privmsg(a, b, c, d, True),
"": handler.unhandled},
host=botconfig.HOST,
port=botconfig.PORT,
authname=botconfig.USERNAME,
@ -44,8 +44,8 @@ def main():
real_name=botconfig.REALNAME,
sasl_auth=botconfig.SASL_AUTHENTICATION,
use_ssl=botconfig.USE_SSL,
connect_cb=modules.common.connect_callback,
stream_handler=tools.stream,
connect_cb=handler.connect_callback,
stream_handler=src.stream,
)
cli.mainLoop()
@ -54,4 +54,4 @@ if __name__ == "__main__":
try:
main()
except Exception:
tools.logger("errors.log")(traceback.format_exc())
src.logger("errors.log")(traceback.format_exc())