From 6050bea0fd5a7f4bdb315227dc52e08e75c2fd6b Mon Sep 17 00:00:00 2001 From: ulhar Date: Fri, 17 Sep 2021 19:12:00 -0400 Subject: [PATCH] initial commit; based on minerobber's cosnok bot --- Gemfile | 3 +++ bot.rb | 26 ++++++++++++++++++++++++++ plugins/hello.rb | 13 +++++++++++++ plugins/help.rb | 29 +++++++++++++++++++++++++++++ plugins/rollcall.rb | 14 ++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 Gemfile create mode 100644 bot.rb create mode 100644 plugins/hello.rb create mode 100644 plugins/help.rb create mode 100644 plugins/rollcall.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..cc6022a --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem 'cinch' diff --git a/bot.rb b/bot.rb new file mode 100644 index 0000000..ec21d9e --- /dev/null +++ b/bot.rb @@ -0,0 +1,26 @@ +require 'cinch' + +# CONFIG +# +botname = 'mechadrake' + +plugins_to_load = [] + +Dir['plugins/*.rb'].each do |plugin| + load plugin + plugins_to_load << Object.const_get(File.basename(plugin, '.rb').capitalize) +end + +bot = Cinch::Bot.new do + configure do |c| + c.server = ENV["IRC_SERVER"] || "127.0.0.1" + c.channels = ["#bot-test"] + c.port = 6667 + c.nick = botname + c.user = botname + c.plugins.plugins = plugins_to_load + c.plugins.prefix = /^#{botname}_*\:? ?/ + end +end + +bot.start \ No newline at end of file diff --git a/plugins/hello.rb b/plugins/hello.rb new file mode 100644 index 0000000..f521c83 --- /dev/null +++ b/plugins/hello.rb @@ -0,0 +1,13 @@ +class Hello + include Cinch::Plugin + + match "hello" + + def execute(m) + m.reply "greetings, #{m.user.nick}" + end + + def help + "hello - bully me into using slightly less sassy language" + end +end diff --git a/plugins/help.rb b/plugins/help.rb new file mode 100644 index 0000000..ac58662 --- /dev/null +++ b/plugins/help.rb @@ -0,0 +1,29 @@ +class Help + include Cinch::Plugin + + match /h[ae]lp(?:\s+(\w+))?/ + + def execute(m, command) + if command.nil? + names = bot.plugins.map do |plugin| + plugin.class.name.downcase + end + m.reply "my sacred powers: #{names.join(", ")}" + else + m.reply "looking for #{command}..." + plug = bot.plugins.first do |plugin| + plugin.class.name.downcase == command + end + + unless plug.nil? + m.reply plug.class.help + else + m.reply "keep trying, buddy. you'll get it eventually." + end + end + end + + def help + "help [command] - figure out how to use one (1) of two (2) commands" + end +end diff --git a/plugins/rollcall.rb b/plugins/rollcall.rb new file mode 100644 index 0000000..2b84de6 --- /dev/null +++ b/plugins/rollcall.rb @@ -0,0 +1,14 @@ +class Rollcall + include Cinch::Plugin + + set :prefix, // + match "!rollcall" + + def execute(m) + m.reply "*yawns* did you miss me?" + end + + def help + "rollcall - respond to !rollcall" + end +end