diff --git a/app/models/ricer/plugins/admin/reboot.rb b/app/models/ricer/plugins/admin/reboot.rb index cdca6c5..127e883 100644 --- a/app/models/ricer/plugins/admin/reboot.rb +++ b/app/models/ricer/plugins/admin/reboot.rb @@ -8,13 +8,18 @@ class Reboot < Ricer::Plugin requires_retype has_usage :execute_reboot + def execute_reboot execute_with_message(t(:default_msg, user:sender.displayname)) end has_usage :execute_with_message, '<..message..>' + def execute_with_message(message) - exec_line "die #{message}" + bot.servers.each do |server| + server.connection.send_quit(@message, message) if server.connected? + end + bot.running = false pid = spawn "bundle exec rake ricer:start" Process.detach(pid) end diff --git a/app/models/ricer/plugins/data/botip.rb b/app/models/ricer/plugins/data/botip.rb new file mode 100644 index 0000000..8b08527 --- /dev/null +++ b/app/models/ricer/plugins/data/botip.rb @@ -0,0 +1,18 @@ +require "open-uri" + +module Ricer::Plugins::Data + class Botip < Ricer::Plugin + + trigger_is :botip + + has_usage :execute + + def execute + Ricer::Thread.execute do + ip = open("http://ipecho.net/plain") + response = ip.read + reply response + end + end + end +end diff --git a/app/models/ricer/plugins/data/google.rb b/app/models/ricer/plugins/data/google.rb new file mode 100644 index 0000000..1603cc2 --- /dev/null +++ b/app/models/ricer/plugins/data/google.rb @@ -0,0 +1,13 @@ +module Ricer::Plugins::Data + class Google < Ricer::Plugin + + trigger_is :google + + has_usage :execute, '<...message...>' + + def execute(message) + google_url = "https://www.google.com/search?q=#{URI::encode(message)}" + reply google_url + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/data/imgur.rb b/app/models/ricer/plugins/data/imgur.rb new file mode 100644 index 0000000..7a787f6 --- /dev/null +++ b/app/models/ricer/plugins/data/imgur.rb @@ -0,0 +1,51 @@ +require 'json' +require 'open-uri' + +module Ricer::Plugins::Data + class Imgur < Ricer::Plugin + + trigger_is :imgur + has_usage :execute + has_usage :execute_msg, '<...message...>' + def execute + Ricer::Thread.execute do + uri = open("https://api.imgur.com/3/gallery/random/random/", + 'Authorization' => 'Client-ID a90bec0cef5bd5c', + 'Accept' => 'application/json' + ) + buffer = uri.read + result = ActiveSupport::JSON.decode(buffer) +# result = JSON.parse(buffer) + id = rand(7) + imgur = result['data'][id] + reply "#{imgur['title']} - #{imgur['link']} \u000303#{imgur['ups']}\u000f\u2934 \u000304#{imgur['downs']}\u000f\u2935" + end + end + + def execute_msg(message) + case message + when "hot" + group = "hot" + when "viral" + group = "viral" + when "top" + group = "top" + else + execute + return false + end + page = rand(4) + Ricer::Thread.execute do + url = open("https://api.imgur.com/3/gallery/#{group}/top/#{page}.json", + 'Authorization' => 'Client-ID a90bec0cef5bd5c', + 'Accept' => 'application/json' + ) + buffer = url.read + result = ActiveSupport::JSON.decode(buffer) + id = rand(7) + imgur = result['data'][id] + reply "#{imgur['title']} - #{imgur['link']} \u000303#{imgur['ups']}\u000f\u2934 \u000304#{imgur['downs']}\u000f\u2935" + end + end + end +end diff --git a/app/models/ricer/plugins/data/lang/en.yml b/app/models/ricer/plugins/data/lang/en.yml new file mode 100644 index 0000000..56f427a --- /dev/null +++ b/app/models/ricer/plugins/data/lang/en.yml @@ -0,0 +1,10 @@ +en: + ricer: + plugins: + data: + imgur: + description: 'Displays a random image from imgur.' + botip: + description: 'Displays the bot ip.' + weather: + description: 'Displays the weather of the given city or country' diff --git a/app/models/ricer/plugins/data/weather.rb b/app/models/ricer/plugins/data/weather.rb new file mode 100644 index 0000000..8ad4d32 --- /dev/null +++ b/app/models/ricer/plugins/data/weather.rb @@ -0,0 +1,25 @@ +require "nokogiri" +require "open-uri" + +module Ricer::Plugins::Data + class Weather < Ricer::Plugin + + trigger_is :weather + + has_usage :execute, '<...message...>' + + def execute(city) + url = "http://api.openweathermap.org/data/2.5/forecast?q=#{city}&mode=xml" + Ricer::Thread.execute do + doc = Nokogiri::XML(open(url), nil, "UTF-8") + data = doc.xpath("//temperature").first + temp = data.attr("value") + city = city + min = data.attr("min") + max = data.attr("max") + # set.each {|s| reply s.to_s} + reply "The temperature is around #{temp} celsius in #{city} and the minimum temperature is #{min} while the maximum temperature is #{max}" + end + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/data/ytsearch.rb b/app/models/ricer/plugins/data/ytsearch.rb new file mode 100644 index 0000000..d96bf3e --- /dev/null +++ b/app/models/ricer/plugins/data/ytsearch.rb @@ -0,0 +1,12 @@ +module Ricer::Plugins::Data + class Ytsearch < Ricer::Plugin + + trigger_is :ytsearch + + has_usage :execute, '<...message...>' + + def execute(message) + rply :link, message:message + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/fun/bed.rb b/app/models/ricer/plugins/fun/bed.rb new file mode 100644 index 0000000..ffc1971 --- /dev/null +++ b/app/models/ricer/plugins/fun/bed.rb @@ -0,0 +1,16 @@ +module Ricer::Plugins::Fun + class Bed < Ricer::Plugin + + trigger_is :bed + + has_usage :execute + + def execute() + user = sender.name + case rand(0..1) + when 0; rply :bed1, user:user + when 1; rply :bed2, user:user + end + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/fun/cat.rb b/app/models/ricer/plugins/fun/cat.rb new file mode 100644 index 0000000..0bd9e59 --- /dev/null +++ b/app/models/ricer/plugins/fun/cat.rb @@ -0,0 +1,16 @@ +module Ricer::Plugins::Fun + class Cat < Ricer::Plugin + + trigger_is :cat + + has_usage :execute + + def execute() + case rand(0..2) + when 0; rply :cat1 + when 1; rply :cat2 + when 2; rply :cat3 + end + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/fun/lang/en.yml b/app/models/ricer/plugins/fun/lang/en.yml index 8dd63eb..d262e63 100644 --- a/app/models/ricer/plugins/fun/lang/en.yml +++ b/app/models/ricer/plugins/fun/lang/en.yml @@ -11,3 +11,18 @@ en: tumbleweed: 'makes the tumbleweed sound.' happy_hour: description: 'Used by gizmore to inititate happy hour mode in #wechall' + reverse: + description: 'Reverses a string backwards.' + wtf: + description: 'gets the word meaning from urbandictionary.' + err_not_found: 'Not found.' + msg_example: "Example: %{example}" + bed: + description: 'You can use this function to goto bed.' + bed1: 'nighty night %{user}' + bed2: 'good night %{user}' + cat: + description: 'Dog sees a cat!' + cat1: 'Bark! Bark!' + cat2: 'Woof! Woof!' + cat3: 'Shrug!' diff --git a/app/models/ricer/plugins/fun/reverse.rb b/app/models/ricer/plugins/fun/reverse.rb new file mode 100644 index 0000000..7a8f6fd --- /dev/null +++ b/app/models/ricer/plugins/fun/reverse.rb @@ -0,0 +1,10 @@ +module Ricer::Plugins::Fun + class Reverse < Ricer::Plugin + + trigger_is :reverse + has_usage :execute_reverse, '<...message...>' + def execute_reverse(message) + reply message.reverse + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/fun/wtf.rb b/app/models/ricer/plugins/fun/wtf.rb new file mode 100644 index 0000000..cd61def --- /dev/null +++ b/app/models/ricer/plugins/fun/wtf.rb @@ -0,0 +1,21 @@ +require 'nokogiri' +require 'open-uri' + +module Ricer::Plugins::Fun + class Wtf < Ricer::Plugin + + trigger_is :wtf + + has_usage :wtf, '<...message...>' + + def wtf(message) + message.gsub!(/\s/, '+') + ud = 'http://www.urbandictionary.com/define.php?term=' + message + doc = Nokogiri::HTML(open(ud), nil, 'UTF-8') + meaning = doc.at_css('.meaning').content.strip + example = doc.at_css('.example').content.strip + reply meaning + reply "Example: " + example + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/tcp/close.rb b/app/models/ricer/plugins/tcp/close.rb new file mode 100644 index 0000000..7572d68 --- /dev/null +++ b/app/models/ricer/plugins/tcp/close.rb @@ -0,0 +1,15 @@ +require 'socket' + +require_relative 'connect' + +module Ricer::Plugins::Tcp + class Close < Ricer::Plugin + def execute_close + tcp_connection = sender.instance_variable_get(:@ricer_tcp_plugin_connection) + unless tcp_connection.nil? + tcp_connection.close + reply "Previous connection closed" + end + end + end +end diff --git a/app/models/ricer/plugins/tcp/connect.rb b/app/models/ricer/plugins/tcp/connect.rb new file mode 100644 index 0000000..8078429 --- /dev/null +++ b/app/models/ricer/plugins/tcp/connect.rb @@ -0,0 +1,43 @@ +require 'socket' + +require_relative 'disconnect' +require_relative 'submit' + +module Ricer::Plugins::Tcp + class Connect < Ricer::Plugin + + permission_is :voice + + trigger_is :connect + + has_usage :connect, ' ' + + def connect(host, port) + tcp_connection = sender.instance_variable_get(:@ricer_tcp_plugin_connection) + unless tcp_connection.nil? + get_plugin('Tcp/Close').execute_close + end + Ricer::Thread.execute do + begin + socket = TCPSocket.open(host, port) + if socket + reply "Connected" + else + reply "Couldn't connect" + end + + + # response = socket.read + # reply response + + #user.instance_variable_set(:@ricer_tcp_plugin_connection, socket) + sender.instance_variable_set(:@ricer_tcp_plugin_connection, socket) + sender.instance_variable_set(:@ricer_tcp_plugin_host, host) + sender.instance_variable_set(:@ricer_tcp_plugin_port, port) + rescue => se + byebug + end + end + end + end +end diff --git a/app/models/ricer/plugins/tcp/current.rb b/app/models/ricer/plugins/tcp/current.rb new file mode 100644 index 0000000..6e33db2 --- /dev/null +++ b/app/models/ricer/plugins/tcp/current.rb @@ -0,0 +1,21 @@ +module +require_relative 'connect' + +permission_is :voice + +trigger_is :current + +has_usage :execute + +def execute + tcp_connection = sender.instance_variable_get(:@ricer_tcp_plugin_connection) + if tcp_connection.nil? + reply "You are not connected to anything yet!" + else + host = sender.instance_variable_get(:@ricer_tcp_plugin_host) + port = sender.instance_variable_get(:@ricer_tcp_plugin_port) + reply host unless host.nil? + reply port unless port.nil? + end + +end diff --git a/app/models/ricer/plugins/tcp/disconnect.rb b/app/models/ricer/plugins/tcp/disconnect.rb new file mode 100644 index 0000000..ffaca46 --- /dev/null +++ b/app/models/ricer/plugins/tcp/disconnect.rb @@ -0,0 +1,26 @@ +require 'socket' + +require_relative 'connect' +require_relative 'submit' + +module Ricer::Plugins::Tcp + class Disconnect < Ricer::Plugin + + permission_is :voice + + trigger_is :disconnect + + has_usage :disconnect + + def disconnect + tcp_connection = sender.instance_variable_get(:@ricer_tcp_plugin_connection) + if tcp_connection.nil? + reply "You are not connected to anything yet!" + else + sender.remove_instance_variable(:@ricer_tcp_plugin_connection) + tcp_connection.close + reply "Closed connection" + end + end + end +end diff --git a/app/models/ricer/plugins/tcp/export/host_param.rb b/app/models/ricer/plugins/tcp/export/host_param.rb new file mode 100644 index 0000000..d4a6a1e --- /dev/null +++ b/app/models/ricer/plugins/tcp/export/host_param.rb @@ -0,0 +1,7 @@ +module Ricer::Plug::Params + class HostParam < Base + def convert_in!(input, option, message) + input + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/tcp/export/port_param.rb b/app/models/ricer/plugins/tcp/export/port_param.rb new file mode 100644 index 0000000..4b30034 --- /dev/null +++ b/app/models/ricer/plugins/tcp/export/port_param.rb @@ -0,0 +1,7 @@ +module Ricer::Plug::Params + class PortParam < Base + def convert_in!(input, option, message) + input + end + end +end \ No newline at end of file diff --git a/app/models/ricer/plugins/tcp/submit.rb b/app/models/ricer/plugins/tcp/submit.rb new file mode 100644 index 0000000..17228c5 --- /dev/null +++ b/app/models/ricer/plugins/tcp/submit.rb @@ -0,0 +1,30 @@ +require 'socket' + +require_relative 'connect' +require_relative 'disconnect' + +module Ricer::Plugins::Tcp + class Submit < Ricer::Plugin + permission_is :voice + trigger_is :submit + has_usage :submit, '<...message...>' + + def submit(message) + Ricer::Thread.execute do + tcp_connection = sender.instance_variable_get(:@ricer_tcp_plugin_connection) + if tcp_connection.nil? + reply "You aren't connected to anything yet!" + else + tcp_connection.send("#{message}") + reply "Sending message..." + if response = tcp_connection.recv(1000) + reply response unless response.nil? + else + reply "Nothing was returned" + end + #byebug + end + end + end + end +end diff --git a/app/models/ricer/plugins/tcp/tcp.rb b/app/models/ricer/plugins/tcp/tcp.rb new file mode 100644 index 0000000..8952085 --- /dev/null +++ b/app/models/ricer/plugins/tcp/tcp.rb @@ -0,0 +1,10 @@ +module Ricer::Plugins::Tcp + class Tcp < Ricer::Plugin + + has_subcommand :connect + has_subcommand :submit + has_subcommand :disconnect + has_subcommand :current + + end +end