discordcr-plugin
Version, currently master branch1 version
- master branchlatestJul 14, 2019
github.com/z64/discordcr-plugin
Proof of concept for collections of event handlers for meew0/discordcr using annotations
2 stars
1 dependent
License: MIT
Installation
# Add this to your shard.yml
dependencies:
discordcr-plugin:
github: z64/discordcr-plugin
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.29.0- License
- MIT
- Author
- Zac Nowicki
- Target
examplefrom examples/main.cr
Dependencies
Development Dependencies
- discordcr*github: z64/discordcr, branch: masterdev
README
discordcr-plugin
TODO: Write a description here
Installation
Add this to your application's shard.yml:
dependencies:
discordcr-plugin:
github: z64/discordcr-plugin
Usage
# my_commands.cr
# Describe a plugin with two middleware that will filter incoming
# events for every event handler in this plugin
@[Discord::Plugin::Options(middleware: {Prefix.new("!"), ChannelFilter.new(123)})]
class MyCommands
include Discord::Plugin
# Create a message_create handler method
@[Discord::Handler(event: :message_create)]
def do_something(payload, ctx)
# Access the client anywhere:
client.create_message(payload.channel_id, "test")
end
@[Discord::Handler(event: :message_create)]
def command_b(payload, ctx)
# ..
end
# Functions without annotations are ignored, can be defined for internal
# helper methods
def some_helper_function(arg)
# ..
end
# Use JSON/YAML configure hooks:
record Config, some_option : Bool do
include JSON::Serializable
include YAML::Serializable
end
@config : Config?
def configure(parser : JSON::PullParser)
@config = Config.new(parser)
end
def configure(parser : YAML::PullParser)
@config = Config.new(parser)
end
end
# main.cr
require "discordcr-plugin"
require "./my_commands"
# Make a client (or many!)
client = Discord::Client.new(token: ENV["TOKEN"])
# Configure all plugins based on their class name:
File.open("config.json", "r") do |file|
parser = JSON::PullParser.new(file)
parser.read_object do |key|
Discord::Plugin.plugins.each do |plugin|
if plugin.class.to_s.underscore == key
plugin.configure(parser)
else
parser.skip
end
end
end
end
# Register all plugins defined across the codebase:
Discord::Plugin.plugins.each do |plugin|
client.register(plugin)
end
# Let's go!
client.run
TODO: Write usage instructions here
Contributors
- z64 Zac Nowicki - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Jul 14, 2019
- Crystal
0.29.0- Indexed
- yes
Dependents
Repository
github.com/z64/discordcr-plugin
Metadata
- Created
- Sep 3, 2026
- Updated
- Sep 8, 2026
- Synced
- Sep 8, 2026
- Versions
- 1