Move files around and update references
This commit is contained in:
parent
5264a2a0da
commit
378334478c
@ -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()
|
|
@ -1 +0,0 @@
|
|||||||
# PLACEHOLDER, DO NOT DELETE THIS FILE
|
|
@ -1,4 +1,57 @@
|
|||||||
|
import argparse
|
||||||
import botconfig
|
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 datetime
|
||||||
import time
|
import time
|
||||||
|
|
@ -11,8 +11,8 @@
|
|||||||
from oyoyo.parse import parse_nick
|
from oyoyo.parse import parse_nick
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import botconfig
|
import botconfig
|
||||||
import settings.wolfgame as var
|
import src.settings as var
|
||||||
from tools import logger
|
from src import logger
|
||||||
|
|
||||||
adminlog = logger(None)
|
adminlog = logger(None)
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
# The bot commands implemented in here are present no matter which module is loaded
|
# The bot commands implemented in here are present no matter which module is loaded
|
||||||
|
|
||||||
import botconfig
|
import botconfig
|
||||||
from tools import decorators
|
from src import decorators
|
||||||
import tools.moduleloader as ld
|
|
||||||
import traceback
|
import traceback
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from oyoyo.parse import parse_nick
|
from oyoyo.parse import parse_nick
|
||||||
import imp
|
import imp
|
||||||
from tools import logger
|
from src import logger
|
||||||
import socket
|
import socket
|
||||||
import settings.wolfgame as var
|
from src import settings as var
|
||||||
|
from src import wolfgame
|
||||||
|
|
||||||
log = logger("errors.log")
|
log = logger("errors.log")
|
||||||
alog = logger(None)
|
alog = logger(None)
|
||||||
@ -37,7 +37,6 @@ def notify_error(cli, chan, target_logger):
|
|||||||
|
|
||||||
|
|
||||||
def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||||
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
prefixes = getattr(var, "STATUSMSG_PREFIXES")
|
prefixes = getattr(var, "STATUSMSG_PREFIXES")
|
||||||
@ -54,8 +53,8 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
if chan == botconfig.NICK:
|
if chan == botconfig.NICK:
|
||||||
chan = parse_nick(rawnick)[0]
|
chan = parse_nick(rawnick)[0]
|
||||||
|
|
||||||
if currmod and "" in currmod.COMMANDS.keys():
|
if "" in wolfgame.COMMANDS.keys():
|
||||||
for fn in currmod.COMMANDS[""]:
|
for fn in wolfgame.COMMANDS[""]:
|
||||||
try:
|
try:
|
||||||
fn(cli, rawnick, chan, msg)
|
fn(cli, rawnick, chan, msg)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -65,7 +64,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
notify_error(cli, chan, log)
|
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):
|
if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
|
||||||
break # channel message but no prefix; ignore
|
break # channel message but no prefix; ignore
|
||||||
if msg.lower().startswith(botconfig.CMD_CHAR+x):
|
if msg.lower().startswith(botconfig.CMD_CHAR+x):
|
||||||
@ -75,7 +74,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if not h or h[0] == " ":
|
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:
|
try:
|
||||||
fn(cli, rawnick, chan, h.lstrip())
|
fn(cli, rawnick, chan, h.lstrip())
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -84,15 +83,13 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
else:
|
else:
|
||||||
notify_error(cli, chan, log)
|
notify_error(cli, chan, log)
|
||||||
|
|
||||||
|
|
||||||
def __unhandled__(cli, prefix, cmd, *args):
|
def unhandled(cli, prefix, cmd, *args):
|
||||||
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
if cmd in set(list(HOOKS.keys()) + list(wolfgame.HOOKS.keys())):
|
||||||
|
|
||||||
if cmd in set(list(HOOKS.keys())+(list(currmod.HOOKS.keys()) if currmod else list())):
|
|
||||||
largs = list(args)
|
largs = list(args)
|
||||||
for i,arg in enumerate(largs):
|
for i,arg in enumerate(largs):
|
||||||
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
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:
|
try:
|
||||||
fn(cli, prefix, *largs)
|
fn(cli, prefix, *largs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -123,11 +120,8 @@ def connect_callback(cli):
|
|||||||
|
|
||||||
cli.cap("REQ", "extended-join")
|
cli.cap("REQ", "extended-join")
|
||||||
cli.cap("REQ", "account-notify")
|
cli.cap("REQ", "account-notify")
|
||||||
|
|
||||||
try:
|
wolfgame.connect_callback(cli)
|
||||||
ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli)
|
|
||||||
except AttributeError:
|
|
||||||
pass # no connect_callback for this one
|
|
||||||
|
|
||||||
cli.nick(botconfig.NICK) # very important (for regain/release)
|
cli.nick(botconfig.NICK) # very important (for regain/release)
|
||||||
|
|
||||||
@ -191,15 +185,4 @@ def connect_callback(cli):
|
|||||||
def on_ping(cli, prefix, server):
|
def on_ping(cli, prefix, server):
|
||||||
cli.send('PONG', 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:
|
# vim: set expandtab:sw=4:ts=4:
|
@ -20,10 +20,10 @@
|
|||||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
from oyoyo.parse import parse_nick
|
from oyoyo.parse import parse_nick
|
||||||
import settings.wolfgame as var
|
import src.settings as var
|
||||||
import botconfig
|
import botconfig
|
||||||
import traceback
|
import traceback
|
||||||
from tools import decorators
|
from src import decorators
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import threading
|
import threading
|
||||||
import copy
|
import copy
|
||||||
@ -36,7 +36,7 @@ import math
|
|||||||
import random
|
import random
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
import signal
|
||||||
from tools import logger
|
from src import logger
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
@ -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"
|
|
16
wolfbot.py
16
wolfbot.py
@ -26,15 +26,15 @@ from oyoyo.client import IRCClient
|
|||||||
import botconfig
|
import botconfig
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import modules.common
|
import src
|
||||||
import tools
|
from src import handler
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
cli = IRCClient(
|
cli = IRCClient(
|
||||||
{"privmsg": modules.common.on_privmsg,
|
{"privmsg": handler.on_privmsg,
|
||||||
"notice": lambda a, b, c, d: modules.common.on_privmsg(a, b, c, d, True),
|
"notice": lambda a, b, c, d: handler.on_privmsg(a, b, c, d, True),
|
||||||
"": modules.common.__unhandled__},
|
"": handler.unhandled},
|
||||||
host=botconfig.HOST,
|
host=botconfig.HOST,
|
||||||
port=botconfig.PORT,
|
port=botconfig.PORT,
|
||||||
authname=botconfig.USERNAME,
|
authname=botconfig.USERNAME,
|
||||||
@ -44,8 +44,8 @@ def main():
|
|||||||
real_name=botconfig.REALNAME,
|
real_name=botconfig.REALNAME,
|
||||||
sasl_auth=botconfig.SASL_AUTHENTICATION,
|
sasl_auth=botconfig.SASL_AUTHENTICATION,
|
||||||
use_ssl=botconfig.USE_SSL,
|
use_ssl=botconfig.USE_SSL,
|
||||||
connect_cb=modules.common.connect_callback,
|
connect_cb=handler.connect_callback,
|
||||||
stream_handler=tools.stream,
|
stream_handler=src.stream,
|
||||||
)
|
)
|
||||||
cli.mainLoop()
|
cli.mainLoop()
|
||||||
|
|
||||||
@ -54,4 +54,4 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except Exception:
|
except Exception:
|
||||||
tools.logger("errors.log")(traceback.format_exc())
|
src.logger("errors.log")(traceback.format_exc())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user