#!/usr/bin/env python3
# This file is placed in the Public Domain.

import os, sys ; sys.path.insert(0, os.getcwd())

from gcd.bus import Bus
from gcd.evt import Command
from gcd.irc import Cfg
from gcd.hdl import Client, cmd
from gcd.obj import boot, cfg
from gcd.nms import Names
from gcd.trc import exception
from gcd.trm import exec
from gcd.zzz import os, sys

__version__ = 30

Cfg.channel = "#genocide"
Cfg.nick = "genocide"

class Console(Client):

    prompt = True

    def handle(self, e):
        super().handle(e)
        e.wait()

    def poll(self):
        if Console.prompt:
            return input("> ")

    def raw(self, txt):
        sys.stdout.write(txt + "\n")
        sys.stdout.flush()

def ver(event):
    event.reply("GENOCIDE %s" % __version__)

def main():
    Names.walk("genocide")
    cfg.name = "gcd"
    c = Console()
    c.boot()
    c.add("ver", ver)
    c.scan(os.path.join(os.getcwd(), "mod"))
    if cfg.txt:
        Console.prompt = False
        e = c.event(cfg.otxt)
        cmd(c, e)
        e.wait()
    elif cfg.mods:
        c.start()
        c.init(cfg.mods)
        c.wait()

exec(main)
