Browse Source

Update building_block_commands.md

pull/56/head
Jari (LotU) 8 years ago
committed by GitHub
parent
commit
640f285765
  1. 30
      docs/bot_tutorial/building_block_commands.md

30
docs/bot_tutorial/building_block_commands.md

@ -70,4 +70,34 @@ def on_add_command(self, event, args):
All combined commands in 1 large codeblock: All combined commands in 1 large codeblock:
```py ```py
class myPlugin(Plugin): class myPlugin(Plugin):
@Plugin.command('ping')
def on_ping_command(self, event):
event.msg.reply('Pong!')
@Plugin.command('echo', '<content:str...>')
def on_echo_command(self, event, content):
event.msg.reply(content)
@Plugin.command('add', '<a:int> <b:int>', group='math')
def on_add_command(self, event, a, b):
event.msg.reply('{}'.format(a+b))
@Plugin.command('tag', '<name:str> [value:str...]')
def on_tag_command(self, event, name, value=None):
tags = self.storage.guild.ensure('tags')
if value:
tags[name] = value
event.msg.reply(':ok_hand: created tag `{}`'.format(name))
else:
if name in tags:
return event.msg.reply(tags[name])
else:
return event.msg.reply('Unknown tag: `{}`'.format(name))
@Plugin.command('add', parser=True, group='math')
@Plugin.parser.add_argument('a', type=int)
@Plugin.parser.add_argument('b', type=int)
def on_add_command(self, event, args):
event.msg.reply('{}'.format(args.a + args.b)
```

Loading…
Cancel
Save