Sha256: 8af56f28b5b2ece0313fceacdf3aa966437f6df565f7852a91a083e547a48375

Contents?: true

Size: 1.53 KB

Versions: 20

Compression:

Stored size: 1.53 KB

Contents

# Plugin-development-tutorial

## Preparing environment
You have 2 ways of creating plugins:

### Gem. This way is recommended.
Create gem by doing `bundler gem <gemname>`. Ensure that this name is not taken on https://rubygems.org.

Create `lib/<gemname>/plugin.rb` file, where `gemname` - name of your gem with `-` replaced with `/`:

```ruby
# Your requires here...

ProtonBot::Plugin.new do
  @name = 'My first plugin'
  @version = MyAmazingGem::VERSION
  @description = 'Yay! First plugin!'

  # Adding permissions using permission API (described in core_plugin.md)
  core.permhash['admin'] << 'my_new_plugin'
  core.permhash['my_new_plugin'] = %w(
    my_sample_permission
  )

  # Hooking to `001` (WELCOME) code:
  hook(type: :code, code: @numeric::WELCOME) do |dat|
    # Do something...
  end

  # Hooking to command `ohaider`. This command cannot be run by users without
  # permission 'my_sample_permission'
  cmd(cmd: 'ohaider') do |dat|
    dat.reply "Ohaider! Your nickname: #{dat[:nick]}. " +
      "Your username: #{dat[:plug].getuser(dat[:nick])}. " +
      "Your hostname: #{dat[:plug].gethost(dat[:nick])}. "
  end.perm!('my_sample_permission')
end
```

Command arguments can always be accessed by `dat[:split]` array.

Now you just need to install your gem (`rake install`) and add it to bot by writing `gem 'gemname'` in `plugin_loader` statement

### Folder in plugins/ directory
Same as above, but instead of creating new gem, you are just creating folder `plugins/folder_name` and adding `plugin('folder_name')` to `plugin_loader` statement

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
protonbot-0.3.7 PLUGIN.md
protonbot-0.3.6 PLUGIN.md
protonbot-0.3.5 PLUGIN.md
protonbot-0.3.4 PLUGIN.md
protonbot-0.3.3 PLUGIN.md
protonbot-0.3.2 PLUGIN.md
protonbot-0.3.1 PLUGIN.md
protonbot-0.3.0 PLUGIN.md
protonbot-0.2.7 PLUGIN.md
protonbot-0.2.6 PLUGIN.md
protonbot-0.2.5 PLUGIN.md
protonbot-0.2.4 PLUGIN.md
protonbot-0.2.3 PLUGIN.md
protonbot-0.2.2 PLUGIN.md
protonbot-0.2.1 PLUGIN.md
protonbot-0.2.0 PLUGIN.md
protonbot-0.1.3 PLUGIN.md
protonbot-0.1.2 PLUGIN.md
protonbot-0.1.1 PLUGIN.md
protonbot-0.1.0 PLUGIN.md