<commit_before>require "cgi"

module Cinch
  module Plugins
    class Trellolistener
      include Cinch::Plugin

      set :plugin_name, 'trellolistener'

      listen_to :api_callback

      def listen(m, json)
        hash = Yajl::Parser.parse(URI.unescape(json))
        bot.loggers.debug(hash.inspect)
        if  @bot.config.options['cogconf']['trello']
        @bot.config.options['cogconf']['trello']['announce'].each do |channel|
          action = hash['action']['type']
	  case action
	  when 'createCard'
          Channel(channel).msg "%s %s created in %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:orange, hash['action']['data']['list']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  when 'updateCard'
          Channel(channel).msg "%s %s moved in %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:orange, hash['action']['data']['list']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  when 'addLabelToCard'
          Channel(channel).msg "%s %s labelled as %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:green, hash['action']['data']['label']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  when 'removeLabelFromCard'
          Channel(channel).msg "%s %s unlabelled as %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:grey, hash['action']['data']['label']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  end
        end
        end
      end

      def link(x)
        "https://trello.com/c/#{x}"
      end

    end
  end
end
<commit_msg>more trello listening knowledge<commit_after>require "cgi"

module Cinch
  module Plugins
    class Trellolistener
      include Cinch::Plugin

      set :plugin_name, 'trellolistener'

      listen_to :api_callback

      def listen(m, json)
        hash = Yajl::Parser.parse(URI.unescape(json))
        bot.loggers.debug(hash.inspect)
        if  @bot.config.options['cogconf']['trello']
        @bot.config.options['cogconf']['trello']['announce'].each do |channel|
          action = hash['action']['type']
	  case action
	  when 'createCard'
          Channel(channel).msg "%s %s created in %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:orange, hash['action']['data']['list']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  when 'updateCard'
          Channel(channel).msg "%s %s moved in %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:orange, hash['action']['data']['list']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  when 'addLabelToCard'
          Channel(channel).msg "%s %s labelled as %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:green, hash['action']['data']['label']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  when 'removeLabelFromCard'
          Channel(channel).msg "%s %s unlabelled as %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            Format(:grey, hash['action']['data']['label']['name']),
            hash['action']['data']['card']['name'],
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  when 'commentCard'
          Channel(channel).msg "%s %s commented on \"%s\" in %s: %s %s" % [
            Format(:yellow, "[%s]" % hash['action']['data']['board']['name']),
            Format(:aqua, hash['action']['memberCreator']['username']),
            truncate(hash['action']['data']['card']['name']),
            Format(:orange, hash['action']['data']['list']['name']),
            truncate(hash['action']['data']['text']),
            Format(:grey, "(%s)" % link(hash['action']['data']['card']['shortLink']))
          ]
	  end
        end
        end
      end

      def link(x)
        "https://trello.com/c/#{x}"
      end

      def truncate(content, limit=50)
        message = ''
        words = content.gsub(/[\s\n]+/," ").split(" ")
        while words.count > 0
           word = words.shift
          if (message.size + word.size + 2) > limit
            message << ' …'
            words.clear
          else
            message << " #{word}"
          end
        end
        message.strip
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.23287904599659284, 'fraction_numerical': 0.0006814310051107325, 'mean_word_length': 2.7276190476190476, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '891262', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1689, 'n_words': 304}