Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!
In our support boards we aim to provide support for the B3 core in its current state. Older releases of B3 are NOT supported. Check our front page for the latest version. You may post feature requests in our General Discussion board. Modifications and Hacks of the core B3 code are NOT supported.
Before you ask for support: [ Read the Support Instructions ] - More info: [ Full Support Disclaimer ]

Author Topic: self is not defined? making a BASIC plug  (Read 1597 times)

Offline Evoium

  • Newbie
  • *
  • Posts: 6
self is not defined? making a BASIC plug
« on: July 13, 2014, 06:19:45 AM »
hey all evo here

i have been trying for the past 8 hours on coding a plugin which works in theory

but my b3 bot wont even make the basicest plug work?

this is the error i get my my b3 log


140713 16:17:32   DEBUG   'Register Event: Program Exit: XlrstatsPlugin'
140713 16:17:32   BOT       'Plugin xlrstats (2.7.1 - Tim ter Laak / Mark Weirath) loaded'
140713 16:17:32   BOT       'Loading Plugin #7 testplug [/home/b3_1.9.1/b3/conf/plugin_testplug.xml]'
140713 16:17:32   INFO   'testplug is not a built-in plugin (No module named testplug)'
140713 16:17:32   INFO   'trying external plugin directory : /home/b3_1.9.1/b3/extplugins'
140713 16:17:32   ERROR   'Error loading plugin testplug'
Traceback (most recent call last):
  File "/home/b3_1.9.1/b3/parser.py", line 674, in loadPlugins
    self._plugins[plugin_name] = getattr(pluginModule, '%sPlugin' % plugin_name.title())(self, plugin_conf)
AttributeError: 'module' object has no attribute 'TestplugPlugin'
140713 16:17:32   BOT       'Loading Plugin publist'
140713 16:17:32   BOT       'PublistPlugin: No config file found for PublistPlugin. (was not required either)'
140713 16:17:32   DEBUG   'Register Event: Stop Process: PublistPlugin'
140713 16:17:32   DEBUG   'Register Event: Program Exit: PublistPlugin'
140713 16:17:32   BOT       'Plugin publist (1.10.2 - ThorN, Courgette) loaded'
140713 16:17:32   DEBUG   'creating the event queue with size 50'


why is this not working?

i literally just want to register a command that says something when you enter the !command




my plugin code so far called testplug

__version__ = '1.0'
__author__  = 'abc'
 
import b3
import b3.events
import b3.plugin

class Tutorial1Plugin(b3.plugin.Plugin):
 
    def onStartup(self):
        # get the admin plugin so we can register commands
        self._adminPlugin = self.console.getPlugin('admin')


        if not self._adminPlugin:
            # something is wrong, can't start without admin plugin
            self.error('Could not find admin plugin')
            return


    self.load_adminPlugin.registerCommand(self, 'test', 2, self.test)


def test(self, data, client, cmd):
   """this is a test"""
   client.message('bar')

 

thanks for the help Evo

Offline Fenix

  • Dev. Team
  • Hero Member
  • *
  • Posts: 981
    • GitHub
Re: self is not defined? making a BASIC plug
« Reply #1 on: July 13, 2014, 12:50:20 PM »
If your plugin name is test the plugin class MUST be named TestPlugin. Since you named it Tutorial1Plugin when you load it in your b3.xml you need to specify tutorial1 as plugin name

Offline Evoium

  • Newbie
  • *
  • Posts: 6
Re: self is not defined? making a BASIC plug
« Reply #2 on: July 13, 2014, 11:21:45 PM »
when i tried that it gave me a attribute error. ill try it now see what happens. thanks for the support

*just tried it and this is the new error

140714 09:23:49   INFO   'trying external plugin directory : /home/b3_1.9.1/b3/extplugins'
140714 09:23:49   ERROR   'Error loading plugin testplug'
Traceback (most recent call last):
  File "/home/b3_1.9.1/b3/parser.py", line 674, in loadPlugins
    self._plugins[plugin_name] = getattr(pluginModule, '%sPlugin' % plugin_name.title())(self, plugin_conf)
AttributeError: 'module' object has no attribute 'TestplugPlugin'
140714 09:23:49   BOT       'Loading Plugin publist'
140714 09:23:49   BOT       'PublistPlugin: No config file found for PublistPlugin. (was not required either)'
140714 09:23:49   DEBUG   'Register Event: Stop Process: PublistPlugin'
140714 09:23:49   DEBUG   'Register Event: Program Exit: PublistPlugin'

thanks Evo
« Last Edit: July 13, 2014, 11:26:46 PM by Evoium »

Offline Fenix

  • Dev. Team
  • Hero Member
  • *
  • Posts: 981
    • GitHub
Re: self is not defined? making a BASIC plug
« Reply #3 on: July 14, 2014, 12:57:36 AM »
when i tried that it gave me a attribute error. ill try it now see what happens. thanks for the support

*just tried it and this is the new error

140714 09:23:49   INFO   'trying external plugin directory : /home/b3_1.9.1/b3/extplugins'
140714 09:23:49   ERROR   'Error loading plugin testplug'
Traceback (most recent call last):
  File "/home/b3_1.9.1/b3/parser.py", line 674, in loadPlugins
    self._plugins[plugin_name] = getattr(pluginModule, '%sPlugin' % plugin_name.title())(self, plugin_conf)
AttributeError: 'module' object has no attribute 'TestplugPlugin'
140714 09:23:49   BOT       'Loading Plugin publist'
140714 09:23:49   BOT       'PublistPlugin: No config file found for PublistPlugin. (was not required either)'
140714 09:23:49   DEBUG   'Register Event: Stop Process: PublistPlugin'
140714 09:23:49   DEBUG   'Register Event: Program Exit: PublistPlugin'

thanks Evo


Alright, I guess I didn't explained myself. The plugin name must be used to name the class you are going to create to implement the plugin.

Example:

If your plugin is named foo, your class MUST be named FooPlugin. The B3 parser will construct the name of the class implementing the plugin by appending the "Plugin" suffix to your plugin name, and making the first letter of the plugin name uppecase (in this case "F").

Offline ph03n1x

  • Sr. Member
  • ****
  • Posts: 296
    • Lovers and Haters Urban Terror
Re: self is not defined? making a BASIC plug
« Reply #4 on: July 14, 2014, 03:35:45 AM »
Can't be any clearer than that... It seems evo that you don't really know how to configure B3 whne it comes to plugins...let me try to explain (say what Fenix said, but in another way).

If you are developing a plugin:

1) Name of plugin: foo
2) What you put as "class" in plugin code: FooPlugin
3) What you put in config: foo

----------------------------------------
Now lets use it in your case:-
-----------------------------------------
1) Name of your plugin: Tutorial1

2) You put the "class" in the plugin code: Tutorial1Plugin (good job :) )

Code: [Select]
class Tutorial1Plugin(b3.plugin.Plugin): 


3) What you put in config: tutorial1 (this is why you are getting that error)
eg:
Code: [Select]
<plugin name="tutorial1" />


I hope this explanation helps.

Good luck :)


Offline Evoium

  • Newbie
  • *
  • Posts: 6
Re: self is not defined? making a BASIC plug
« Reply #5 on: July 14, 2014, 05:44:48 AM »
hey guys fixed all that stuff and it finally looks like theres hope :D
so this is the next thing its doing

140714 15:42:31   BOT       'Plugin xlrstats (2.7.1 - Tim ter Laak / Mark Weirath) loaded'
140714 15:42:31   BOT       'Loading Plugin #7 testplug [/home/b3_1.9.1/b3/conf/plugin_testplug.xml]'
140714 15:42:31   INFO   'testplug is not a built-in plugin (No module named testplug)'
140714 15:42:31   INFO   'trying external plugin directory : /home/b3_1.9.1/b3/extplugins'
140714 15:42:31   ERROR   'Error loading plugin testplug'
Traceback (most recent call last):
  File "/home/b3_1.9.1/b3/parser.py", line 674, in loadPlugins
    self._plugins[plugin_name] = getattr(pluginModule, '%sPlugin' % plugin_name.title())(self, plugin_conf)
AttributeError: 'module' object has no attribute 'TestplugPlugin'
140714 15:42:31   BOT       'Loading Plugin publist'
140714 15:42:31   BOT       'PublistPlugin: No config file found for PublistPlugin. (was not required either)'
140714 15:42:31   DEBUG   'Register Event: Stop Process: PublistPlugin'
140714 15:42:31   DEBUG   'Register Event: Program Exit: PublistPlugin'

thanks for all the help guys it rocks

 


Rate this page +1 at Google Search

anything