diff --git a/Gemfile b/Gemfile index e86186d6..a5d9743a 100644 --- a/Gemfile +++ b/Gemfile @@ -12,3 +12,4 @@ gem "shellwords" gem 'nokogiri' gem 'fmylife' gem 'prime' +gem 'pastebinrb' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..ee82fe7e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,35 @@ +GEM + remote: https://rubygems.org/ + specs: + ansirc (1.1.0) + cinch (2.3.4) + fmylife (0.6.0) + forwardable (1.3.2) + nokogiri (1.11.6-x86_64-linux) + racc (~> 1.4) + open-uri (0.1.0) + pastebin (2.1.0) + pastebinrb (1.3.1) + prime (0.1.2) + forwardable + singleton + racc (1.5.2) + shellwords (0.1.0) + singleton (0.1.1) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + ansirc + cinch + fmylife + nokogiri + open-uri + pastebin + pastebinrb + prime + shellwords + +BUNDLED WITH + 2.2.17 diff --git a/classes/Util.rb b/classes/Util.rb index 75d0433d..7452ebf4 100644 --- a/classes/Util.rb +++ b/classes/Util.rb @@ -263,35 +263,48 @@ module Util #utilities and such end module PasteMaker require "pastebin" - @map = { + require "tempfile" + @@map = { post: 'code', title: 'name', raw: "raw", expire: "expire_date", format: "format", } - @opts = { + @@opts = { "api_paste_expire_date" => "1H", "api_paste_format" => "text", "api_paste_name" => "tcpbot paste", - 'api_paste_rawi' => "", + 'api_paste_raw' => "", } def paste(opts) - _opts = @opts + puts "IN PASTE LOL" + puts "@@MAP: #{@@map.inspect}" + puts "@@OPTS: #{@@opts.inspect}" + puts "opts: #{opts.inspect}" + _opts = @@opts.clone + puts "_opts: #{_opts}" if(opts[:post].nil?) + puts "whoops NO POST CYA!!!" return nil end if(opts.is_a? String) + puts "opts came as a string; treating as post" opts = { post: opts } end + datafile = Tempfile.new("Pasty") + datafile.write(opts[:post]) + opts[:post] = datafile.path opts.each do |k,v| - _opts["api_paste_"+@map[k]] = v + _opts["api_paste_"+@@map[k]] = v end puts "options rcvd for paste: #{_opts.inspect}" pb = Pastebin.new(_opts) link = pb.paste puts "got pb link: #{link}" + datafile.close + datafile.unlink return link end end diff --git a/plugins/Artism.rb b/plugins/Artism.rb index 97374b30..64ff7912 100644 --- a/plugins/Artism.rb +++ b/plugins/Artism.rb @@ -14,64 +14,81 @@ class Artism include Util::PluginHelper include Util::PasteMaker set :prefix, /^:/ - @files = [] - @dir = "etc/art/" - @urirxp = URI.regexp %w(http https) @clist = %w{art.list} @@commands["art.list"] = ":art.list [/regex/[i]] - list all the available art to play (it will be a lot lol); optional regex to filter it down (and you can do /regex/i for case insensitivity dawg)"; - match(/art.list (\/(.+)\/(i)?)?/, method: :list_art) + match(/art\.list\s*$/, method: :artlist) + match(/art\.list (\/(.+)\/(i)?)/, method: :artlist) @@commands["art.play"] = ":art.play - play a specific file, :art.list can be used to see what is available" @clist.push "art.play" - match(/art.play (.+)/, method: :play_art) + match(/art\.play (.+)/, method: :play_art) @@commands["art.random"] = "art.random - play a random art file, who cares what it might be?" @clist.push "art.random" - match(/art.random/ , method: :artspew) + match(/art\.random/ , method: :artspew) timer 30.minutes, method: :gather_files - timer 2.seconds, method: :gather_files, shots: 1 #@@commands["art.web"] = "art.web - grab an ANSI file from the internet at , convert it, and play it." #@clist.push "art.web" #match /art.web (#{@urirxp})/, method: :arternets + # + + def initialize(*args) + super + + @files = [] + @dir = "etc/art/" + @urirxp = URI.regexp %w(http https) + gather_files() + end def gather_files() + puts "GATHERING FILES WE ARE GATHERING FILES!" @files = Dir.glob("*", base: @dir) puts "sexy files #{@files.length}" end def play_art(m, art) response = "" - path = "#{@dir}{art}" + path = "#{@dir}#{art}" if !File.exists? path exc = Util::Util.instance.getExcuse() response << "#{m.user.nick}: #{exc} (#{art} does not appear to EXIST smfh lern2type)" else response << "%s %s" % [Format(:red, "Now playing: "), Format(:red, :bold, path)] - response << File.open("etc/art/#{art}") { |file| - file.readlines + response << File.open(path) { |file| + file.read } end m.reply response end - def list_art(m, regex, target, cs) + def artlist(m, *args) + regex, target, cs = args response = "#{m.user.nick}: " + puts " I GRAB MUH NUT IN DA ART LIST" + 3.times do puts "!!!!!!!!!!!!!!!!!!" end + puts "args: #{args}" + puts "regex: #{regex}, target: #{target}. cs: #{cs}" list = [] if(regex.nil?) #no regex provided loil + puts "ig dey want all da smoke" list = @files #just get em ALL TOGETHER else #oh we have a regex i see sluice = cs.nil? ? /#{target}/ : /#{target}/i - list = @files.filter { |file| file.match(sluice) } + puts "sluice = #{sluice}" + list = @files.select { |file| file.match(sluice) } + puts "ok list length = #{list.length}" end if(list.length > 20) - title = "ANSI Art Listing (for #{m.user.nick})" - title << " (q: #{regex})" if !regex.nil? - title << " @ " << Time.now.strftime("%s") + puts "building pastebin thingy..." + title = "ANSI Art List (#{regex})" factors = Prime.prime_division(list.length) - count = factors.detect { |f| f[1] == 1 && f[0] > 2 } + count, power = factors.detect { |f| f[1] == 1 && f[0] > 2 } + puts power count = 5 if count > 7 chunks = list.each_slice(count).to_a - code = list.reduce("") { |memo, line| - memo << line.join(" ") << "\n" - } + puts "chunks: #{chunks}" + code = chunks.map { |chunk| + chunk.join(" ") + }.join("\n") puts "gonna paste this list; info first" puts "title: #{title}" puts "list length: #{list.length}" @@ -80,11 +97,15 @@ class Artism puts "chunks: #{chunks.inspect}" puts" && code to paste: #{code}" response << "#{list.length} results were found; please visit:" - response << "\n" << paste({ - title: title, - post: code - }) << " to see the full list" - gonna have to experiment first lol + begin + response << "\n" << paste({ + title: title, + post: code + }) << " to see the full list" + rescue Exception => ex + response << "SOMETHING MESSED UP: #{ex}" + end + #gonna have to experiment first lol else puts "less than 20 results found yo: #{list.length}" response << "here are the #{list.length} result(s) found.\n" << list.join(", ") @@ -92,7 +113,7 @@ class Artism puts "ultimate response: #{response}" #m.reply response end - def art_spew(m, cmd) + def artspew(m, cmd) play_art(m,@files.sample) end diff --git a/plugins/HHH.rb b/plugins/HHH.rb index 726a77ed..0c376a10 100644 --- a/plugins/HHH.rb +++ b/plugins/HHH.rb @@ -2,70 +2,70 @@ require 'cinch' require_relative '../classes/Util.rb' class HHH - include Util::PluginHelper - include Cinch::Plugin - listen_to :message - $responses = { - :h => - { :match => /^h$/i, :response => "h" }, - :same => - { :match => /^same\s*/i, :response => "[✔] Same" }, - :hi => - { :match => /^hi$/i, :response => "yes helo" }, - :the => - { :match => /^the$/i, :response => "the" }, - :five => - { :match => /^(5 *|(5 )+)$/, :response => (("5 "*5)+"\n")*5 }, - :good_bot => - { :match => /good bot/i, :method => Util::Util.instance.method(:getSuccess)}, - :bad_bot => - { :match => /bad bot/i, :method => Util::Util.instance.method(:getExcuse )}, + include Util::PluginHelper + include Cinch::Plugin + listen_to :message + $responses = { + :h => + { :match => /^h$/i, :response => "h" }, + :same => + { :match => /^same\s*$/i, :response => "[✔] Same" }, + :hi => + { :match => /^hi$/i, :response => "yes helo" }, + :the => + { :match => /^the$/i, :response => "the" }, + :five => + { :match => /^(5 *|(5 )+)$/, :response => (("5 "*5)+"\n")*5 }, + :good_bot => + { :match => /good bot/i, :method => Util::Util.instance.method(:getSuccess)}, + :bad_bot => + { :match => /bad bot/i, :method => Util::Util.instance.method(:getExcuse )}, - } - $can_speak = $responses.map { |k,v| - k.to_sym - } - #puts $can_speak.inspect - $offset = 10 - def listen(m) - msg = m.message - target = "" - response = "" - #puts "canspeak: #{$can_speak.inspect}" - $responses.each { |k, v| - #puts "\ttrying #{msg} against #{v.inspect}" - if msg.match v[:match] - #puts "\t#{msg} matched #{v[:match]}" - target = k - #puts "\ttarget: #{target}, response: #{v[:response]}" - if(v[:method].nil?) - response = v[:response] - else - response = v[:method].call - end - end - } - puts response.inspect - if(idx = $can_speak.find_index { |x| - #puts "\tcomparing #{x} to #{target}" - x == target - }) - m.reply response - #puts "deleting #{target}" - $can_speak.delete(target) - $can_speak.delete("") - #puts $can_speak.inspect - end - Timer($offset, {:shots => 1}) do - unless target == "" or target == nil - #puts "\tpushing #{target} back into canspeak" - $can_speak.push target - end - end if idx - - end - + } + $can_speak = $responses.map { |k,v| + k.to_sym + } + #puts $can_speak.inspect + $offset = 10 + def listen(m) + msg = m.message + target = "" + response = "" + #puts "canspeak: #{$can_speak.inspect}" + $responses.each { |k, v| + #puts "\ttrying #{msg} against #{v.inspect}" + if msg.match v[:match] + #puts "\t#{msg} matched #{v[:match]}" + target = k + #puts "\ttarget: #{target}, response: #{v[:response]}" + if(v[:method].nil?) + response = v[:response] + else + response = v[:method].call + end + end + } + puts response.inspect + if(idx = $can_speak.find_index { |x| + #puts "\tcomparing #{x} to #{target}" + x == target + }) + m.reply response + #puts "deleting #{target}" + $can_speak.delete(target) + $can_speak.delete("") + #puts $can_speak.inspect + end + Timer($offset, {:shots => 1}) do + unless target == "" or target == nil + #puts "\tpushing #{target} back into canspeak" + $can_speak.push target + end + end if idx + + end + end - - + +