<commit_before>#  -*- coding: utf-8 -*-
#  ruby_eval.rb
#  Author: <NAME>
#  ------------------------
#  A Cinch plugin that Ruby evaluation for yossarian-bot.
#  Uses the eval.in service: https://eval.in/
#  ------------------------
#  This code is licensed by <NAME> under the MIT License.
#  http://opensource.org/licenses/MIT

require 'mechanize'
require 'nokogiri'

require_relative 'yossarian_plugin'

class RubyEval < YossarianPlugin
	include Cinch::Plugin

	def initialize(*args)
		super
		@url = 'http://eval.in'
	end

	def usage
		'!rb <code> - Evaluate the given Ruby code on eval.in. Alias: !ruby'
	end

	def match?(cmd)
		cmd =~ /^(!)?(?:rb$)|(?:ruby$)/
	end

	match /(?:rb|ruby) (.+)/, method: :ruby_eval, strip_colors: true

	def ruby_eval(m, code)
		mech = Mechanize.new
		mech.user_agent_alias = 'Linux Firefox'
		page = mech.get(@url)

		begin
			form = page.forms.first
			form.field_with(:name => 'code').value = code
			form.field_with(:name => 'lang').value = "ruby/mri-2.2"
			html = Nokogiri::HTML(mech.submit(form).body)
			results = html.css('pre').last.text.gsub("\n", ' ')

			if results.size > 0 
				m.reply results, true
			else
				m.reply 'No output was produced.', true
			end
		rescue Exception => e
			m.reply e.to_s, true
		end
	end
end<commit_msg>substitute carriage returns and tabs too<commit_after>#  -*- coding: utf-8 -*-
#  ruby_eval.rb
#  Author: <NAME>
#  ------------------------
#  A Cinch plugin that Ruby evaluation for yossarian-bot.
#  Uses the eval.in service: https://eval.in/
#  ------------------------
#  This code is licensed by <NAME> under the MIT License.
#  http://opensource.org/licenses/MIT

require 'mechanize'
require 'nokogiri'

require_relative 'yossarian_plugin'

class RubyEval < YossarianPlugin
	include Cinch::Plugin

	def initialize(*args)
		super
		@url = 'http://eval.in'
	end

	def usage
		'!rb <code> - Evaluate the given Ruby code on eval.in. Alias: !ruby'
	end

	def match?(cmd)
		cmd =~ /^(!)?(?:rb$)|(?:ruby$)/
	end

	match /(?:rb|ruby) (.+)/, method: :ruby_eval, strip_colors: true

	def ruby_eval(m, code)
		mech = Mechanize.new
		mech.user_agent_alias = 'Linux Firefox'
		page = mech.get(@url)

		begin
			form = page.forms.first
			form.field_with(:name => 'code').value = code
			form.field_with(:name => 'lang').value = "ruby/mri-2.2"
			html = Nokogiri::HTML(mech.submit(form).body)
			results = html.css('pre').last.text.gsub(/[\t\r\n]/, ' ')

			if results.size > 0 
				m.reply results, true
			else
				m.reply 'No output was produced.', true
			end
		rescue Exception => e
			m.reply e.to_s, true
		end
	end
end
{'fraction_non_alphanumeric': 0.1867076450249712, 'fraction_numerical': 0.003073376872839032, 'mean_word_length': 2.8181818181818183, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '312162', 'n_tokens_mistral': 1041, 'n_tokens_neox': 938, 'n_words': 240}