forked from crispymtn/crispyfi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class MyFirstPlugin | ||
constructor: () -> | ||
@name = 'My First Plugin' | ||
@response = null | ||
|
||
handle: (auth, spotify, volume) -> | ||
if auth.command == 'plugin' | ||
# This will be replied to the channel. If nothing is set, no reply will be sent. | ||
@response = "This is a reply from #{@name}." | ||
return true | ||
else | ||
return false | ||
|
||
module.exports = () -> | ||
return new MyFirstPlugin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class PluginHandler | ||
constructor: () -> | ||
# Plugin cache | ||
@plugins = [] | ||
|
||
# Adds all plugins to the cache | ||
load_plugins: () -> | ||
# Reset the plugin cache | ||
@plugins = [] | ||
console.log "Loading Plugins..." | ||
root_dir = require('path').dirname require.main.filename | ||
require("fs").readdirSync("#{root_dir}/plugins").forEach (file) => | ||
plugin = require("#{root_dir}/plugins/" + file)() | ||
@plugins.push plugin | ||
console.log " -- #{plugin.name}" | ||
console.log "...done." | ||
return | ||
|
||
handle: (auth, spotify, volume) -> | ||
state = false | ||
for plugin in @plugins | ||
if plugin.handle(auth, spotify, volume) | ||
return plugin.response | ||
|
||
module.exports = () -> | ||
if !@handler? | ||
@handler = new PluginHandler() | ||
@handler.load_plugins() | ||
return @handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters