Python class objects as plugins?

S

sleem

Hi. I'm hacking up an irc bot in python using Joel Rosdahl's irclib.

I want to be able to add plugins to my bot, without having to restart it.

In specific, I would have a directory called "plugins". Into this, I would
place scripts that the bot could load as plugins, whenever I give it the
instruction to "rehash".

I figured the most practical way to do this, is to have each plugin script
file basically contain a class that the program can load as an object.

So I need a subroutine that can import all the classes in the plugins/
directory at start up. When instructed to rehash, it also needs to be able
to destroy all the objects it currently has in memory, and reload all the
class files in the plugins/ directory.

What's the most practical way to do this?

Thanks in advance.
 
S

Sybren Stuvel

sleem enlightened us with:
Hi. I'm hacking up an irc bot in python using Joel Rosdahl's irclib.

I want to be able to add plugins to my bot, without having to
restart it.

Check out Supybot. It is an IRC bot written in Python, with plugin
support. Adding plugins is usually fine, it's the removal of plugins
that might cause problems.
I figured the most practical way to do this, is to have each plugin
script file basically contain a class that the program can load as
an object.

Sounds like a good plan.
So I need a subroutine that can import all the classes in the
plugins/ directory at start up.

I wouldn't do that. Rather, only load plugins that have been
configured to load. It's easier to check the plugin list for things
that you _do_ want, than for things that you _don't_ want.
When instructed to rehash, it also needs to be able to destroy all
the objects it currently has in memory, and reload all the class
files in the plugins/ directory.

Sounds like it would be easier to be able to load and unload single
plugins. It'll be easier to code since you only have to focus on a
single plugin, and you can still apply it to all plugins in sequence.

Sybren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top