https://github.com/andrewda/frc-slack-bot
A Slack bot for FRC teams
https://github.com/andrewda/frc-slack-bot
Last synced: 4 months ago
JSON representation
A Slack bot for FRC teams
- Host: GitHub
- URL: https://github.com/andrewda/frc-slack-bot
- Owner: andrewda
- Created: 2016-09-02T02:36:12.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-25T19:22:55.000Z (over 9 years ago)
- Last Synced: 2025-05-12T19:49:01.298Z (about 1 year ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FRC Slack bot
## Introduction
FRC Slack Bot is a bot originally created for the [South Eugene Robotics Team](https://github.com/SouthEugeneRoboticsTeam) Slack server. It was made to be highly customizable to fit the needs of any team.
## Customization
Customizing the FRC Slack Bot couldn't be easier. You can customize everything - from high-level Plugins which handle commands to low-level Listeners which listen for server events.
### Custom Plugins
Plugins can be created and customized to handle commands. Commands may be something obvious such as "/echo" or "!echo", but may also be something more subtle, such as adding a reaction to a message.
Command files are named by their base command, so if you're creating a "!echo" command, the file would be named "echo.js".
An example Plugin can be found below:
```javascript
module.exports = {
config: {
name: 'Echo',
description: 'Echo the user',
command: 'echo',
syntax: '',
test: true
},
main: function(plugin, events) {
console.log('Plugin Loaded:', plugin.getName(), '-', plugin.getDescription());
events.on('message', function(msg) {
plugin.rtm.sendMessage(plugin.stripCommand(msg.text), msg.channel);
});
}
};
```
Config options:
- `name`: **[required]** The plugin's name
- `description`: **[required]** The plugin's description
- `command`: The command to trigger the plugin
- `syntax`: The command's syntax
- `test`: `true` to emit only messages with the correct command and syntax (default `true` when `command` is defined)
Plugin parameters:
- `plugin`: An instance of SlackBot (found in ../lib/index.js)
- `events`: An EventEmitter object
### Custom Listeners
Listeners must be named after the event they listen for. For example, the file below is named "message.js" and listens for the "message" event. When the event is fired, it will use this function instead of defaulting to a simply emitting the message.
To access `rtm`, `config`, etc., you may reference `this` as all listeners will be executed using the parent scope.
```javascript
module.exports = function(message) {
var identifier = '<@' + this.config.slack.botid + '>'
if (message.text && message.text.split(' ')[0] === identifier) {
message.text = message.text.replace(identifier, '').trim();
if (this.pluginConfig.test || !this.getCommand()) {
if (this.testCommand(message.text)) {
if (this.testSyntax(message.text)) {
this.events.emit('message', message);
} else {
this.rtm.sendMessage(this.getSyntaxMessage(), message.channel);
}
}
} else {
this.events.emit('message', message);
}
}
};
```
Listener parameters:
- `message`: A standard Slack message object