Browse Source

Intial Commit

master
commit
69d939b68c
10 changed files with 161 additions and 0 deletions
  1. +6
    -0
      .gitignore
  2. +21
    -0
      LICENSE
  3. +27
    -0
      README.md
  4. +6
    -0
      shard.lock
  5. +18
    -0
      shard.yml
  6. +9
    -0
      spec/Bundesministcr_spec.cr
  7. +2
    -0
      spec/spec_helper.cr
  8. +47
    -0
      src/Bundesministcr.cr
  9. +17
    -0
      src/Commands.cr
  10. +8
    -0
      src/core.cr

+ 6
- 0
.gitignore View File

@ -0,0 +1,6 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf
config.ini

+ 21
- 0
LICENSE View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 deing
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

+ 27
- 0
README.md View File

@ -0,0 +1,27 @@
# Bundesministcr
TODO: Write a description here
## Installation
TODO: Write installation instructions here
## Usage
TODO: Write usage instructions here
## Development
TODO: Write development instructions here
## Contributing
1. Fork it (<https://github.com/your-github-user/Bundesministcr/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [deing](https://github.com/your-github-user) - creator and maintainer

+ 6
- 0
shard.lock View File

@ -0,0 +1,6 @@
version: 1.0
shards:
discordcr:
github: meew0/discordcr
commit: 1d40f5fa0c9069a817ddbb3daf26782607d69d7d

+ 18
- 0
shard.yml View File

@ -0,0 +1,18 @@
name: Bundesministcr
version: 0.1.0
authors:
- deing <admin@15318.de>
targets:
Bundesministcr:
main: src/Bundesministcr.cr
dependencies:
discordcr:
github: meew0/discordcr
branch: master
crystal: 0.27.2
license: MIT

+ 9
- 0
spec/Bundesministcr_spec.cr View File

@ -0,0 +1,9 @@
require "./spec_helper"
describe Bundesministcr do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end

+ 2
- 0
spec/spec_helper.cr View File

@ -0,0 +1,2 @@
require "spec"
require "../src/Bundesministcr"

+ 47
- 0
src/Bundesministcr.cr View File

@ -0,0 +1,47 @@
require "ini"
require "discordcr"
require "logger"
require "./Commands"
module Bundesministcr
extend self
include BundesministcrCommands
VERSION = "0.1.0"
def load_config(path)
INI.parse(File.read(path))["config"]
end
def load_client(config)
Discord::Client.new(token: "Bot #{config["token"]}", client_id: config["client"].to_u64)
end
def start()
cfg = load_config("config.ini")
client = load_client(cfg)
client.on_message_create do |msg|
next unless msg.content.starts_with?(cfg["prefix"])
content = msg.content.lchop(cfg["prefix"])
arguments = content.split(" ")
command = arguments.shift
next unless COMMANDS_AND_WHERE_TO_FIND_THEM[command]?
output = ""
begin
LOG.info "#{msg.author.username}##{msg.author.discriminator} issued #{command} #{arguments}"
output = COMMANDS_AND_WHERE_TO_FIND_THEM[command][:fun].call(
arguments,
contextualize(msg)
)
rescue e
output = ":x: Error executing command."
LOG.error e
end
client.create_message(msg.channel_id, output)
end
client.run
end
end
LOG = Logger.new(STDOUT, level: Logger::INFO, progname: "Bundesministcr")
Bundesministcr.start

+ 17
- 0
src/Commands.cr View File

@ -0,0 +1,17 @@
require "./core"
module BundesministcrCommands
extend self
include BundesministcrCommandsCore
alias CommandType = Proc(Array(String), CommandContext, CommandResult)
alias CommandContext = {issuer: Discord::User}
alias CommandResult = String
alias CommandInfo = {fun: CommandType, desc: String}
def contextualize(msg : Discord::Message)
{issuer: msg.author}
end
COMMANDS_AND_WHERE_TO_FIND_THEM = {
"ping" => {fun: PING, desc: "Hewwo n_n"}
}
end

+ 8
- 0
src/core.cr View File

@ -0,0 +1,8 @@
require "./Commands"
module BundesministcrCommandsCore
extend self
PING = ->(args : Array(String), ctx : BundesministcrCommands::CommandContext) {
"Pyongyang!"
}
end

Loading…
Cancel
Save