*****DEAD ACCOUNT 8090033f6f | ||
---|---|---|
mcmxi | ||
.gitignore | ||
Pipfile | ||
Pipfile.lock | ||
README.md | ||
conf.example.yml | ||
dev.md |
Quickstart
- This bot uses notices to send information that is personalized or private to you, use one of the following two sections (irssi or weechat)
Irssi
/WINDOW LEVEL +NOTICES
Weechat
/set irc.msgbuffer.notice = current
Bot
pipenv
is required, install it withpip install pipenv
or your OS package manager.- Clone this repository
- copy the configuration example, to
config.yml
and edit it. Not much is required to start, just the obvious settiings. - run
pipenv shell
- run
pipenv sync
- run
python -m mcmxi.mcmxi
Console
- the bot uses IPython embedded for control and development
❯ python -m mcmxi.mcmxi
INFO|mcmxi-><module> bot is initialized, press C-d at any point for a smooth and easy exit, starting REPL...
Python 3.6.10 (default, Jan 16 2020, 09:12:04) [GCC]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
...
Extensibility
- To extend the bot, create a script to the following effect:
from mcmxi import mcmxi
if __name__ == "__main__":
l = UTIL.setup_logging(bot_config())
bots = mcmxi.start_bots()
l.info("bot is initialized, press C-d at any point for a smooth and easy exit, starting REPL...")
IPYSH()
mcmxi.stop_bots(bots)
S.exit()
- then add a tuple containing an instance of a class that contains your fantasy command functions, the prefix of the method names if any or "", and a lambda method call wrapper to any or all of the bot instance's executables list. Each bot has an executable list that looks like this:
self.executables = [
(self,
"cmd",
lambda event, instance: instance(event) ),
(CARD,
"cmd",
lambda event, instance: instance(event) ),
(EXP_EVAL,
"cmd",
lambda event, instance: instance(event) ),
(HTTP,
"cmd",
lambda event, instance: instance(event) ),
(IRC_TXT,
"cmd",
lambda event, instance: instance(event) ),
(TERM_BIN,
"cmd",
lambda event, instance: instance(event) ),
(UTIL,
"cmd",
lambda event, instance: instance(event) ) ]
CARD
is the singleton classcmd
is the prefix for methods that should be exposed as fantasy commandslambda event, instance: instance(event)
is a method call wrapper (default example)
When fantasy commands are sent to a channel, an executor defined in the UTILS
class is invoked,
which is technically also extensible / customizable. The default simply looks for methods in
each of the whitelisted classes (in self.executables
) for method's prefixed with cmd
or
whatever prefix is specified, the rest of the fantasy command that was specified corresponds
directly to the rest of the method name:`
self.executor = (
lambda bot, obj, method_prefix, call_wrapper, event: call_wrapper(
event,
obj.__getattribute__(next(filter(lambda t: (
method_prefix != ""
and "{prefix}_{command}"
or "{prefix}{command}").format(
prefix = method_prefix,
command = t[ 0 ]
) == t[ 1 ] and t[ 1 ], zip(ITER.cycle([event.data(
).arguments[ 0 ].split(" "
)[ 0 ].strip(next(filter(lambda x: x.channel_name(
).lower(
) == event.target().lower(
), bot.conf.channels() )
).command_prefix() ) ]
), dir(obj) ) )
)[ 1 ] ) ) )