-
-
Save maxpowa/18d611b302ebe16748048c2b58690798 to your computer and use it in GitHub Desktop.
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 is part of ircbot.cr | |
# Copyright (C) 2016 Max Gurela <max.gurela@outlook.com> | |
# Original Copyright (C) 2016 Oleh Prypin <oleh@pryp.in> | |
# Released under the terms of the MIT license (see LICENSE). | |
require "./options" | |
require "./module" | |
require "./irc" | |
module IRCBot | |
class ChatOptions < Options | |
string host = "irc.esper.net" | |
int port = 6667 | |
bool ssl = false | |
array channels = ["#irc_bot"] | |
string nick = "irc_bot" | |
string password = nil | |
string username = "irc_bot" | |
string hostname = "*" | |
string realname = "irc_bot.cr" | |
string quit_reason = "Goodbye." | |
string bind_host = "localhost" | |
int bind_port = 9999 | |
int read_timeout = 180 | |
int write_timeout = 5 | |
end | |
class Bot | |
INSTANCE = new | |
@modules = [] of IRCBot::Handler | |
def self.instance | |
INSTANCE | |
end | |
def self.start(options) | |
INSTANCE.start(options) | |
end | |
def self.register(mod) | |
INSTANCE.register(mod) | |
end | |
def start(options) | |
@chat = IRCBot::IRC.new(options) | |
spawn do | |
# When we receive a message | |
@chat.not_nil!.run do |msg| | |
# Async modules so we don't end up being slow | |
@modules.each do |mod| | |
spawn do | |
mod.handle msg | |
end | |
end | |
end | |
end | |
end | |
def register(mod) | |
@modules.push(mod) | |
end | |
macro self.method_missing(call) | |
INSTANCE.@chat.not_nil!.{{call}} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment