diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d3ed4c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.yml diff --git a/config.yml.example b/config.yml.example new file mode 100644 index 0000000..d5bd1cb --- /dev/null +++ b/config.yml.example @@ -0,0 +1,2 @@ +discord_webhook: "" +discord_token: "" diff --git a/questbook.rb b/questbook.rb index efdb98b..a53a64e 100644 --- a/questbook.rb +++ b/questbook.rb @@ -6,6 +6,7 @@ require 'json' require 'formdata' require 'nokogiri' require 'digest' +require 'yaml' require_relative 'plugins/link_info' require_relative 'plugins/help' @@ -25,6 +26,12 @@ class QuestBook include Cinch::Plugin listen_to :questbook + + def initialize(m) + @config = YAML.load_file('config.yml') + super(m) + end + def listen(m) params = FormData.new params.append('msg', '') @@ -53,6 +60,14 @@ class QuestBook if msg[2] != @last and print then Channel('#questbook').send("#{who}: #{msg}") @last = msg[2] + # discord webhook + http = Net::HTTP.new('discordapp.com', 443) + http.use_ssl = true + params = FormData.new + params.append('content', msg[2]) + params.append('username', msg[1]) + req = params.post_request("api/webhooks/#{@config.discord_webhook}/#{@config.discord_token}") + http.request(req) end end end