cinch-urbandict 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/cinch-urbandict.rb
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'cinch'
|
|
3
|
+
require 'cinch/cooldown'
|
|
4
|
+
require 'cinch/toolbox'
|
|
5
|
+
|
|
6
|
+
module Cinch::Plugins
|
|
7
|
+
# Cinch plugin for getting UD defs.
|
|
8
|
+
class UrbanDict
|
|
9
|
+
include Cinch::Plugin
|
|
10
|
+
|
|
11
|
+
enforce_cooldown
|
|
12
|
+
|
|
13
|
+
self.help = 'Use .ud <term> to see the Urban Dictionary definition.'
|
|
14
|
+
|
|
15
|
+
match /ud (.*)/
|
|
16
|
+
|
|
17
|
+
def execute(m, term)
|
|
18
|
+
m.reply get_def(term), true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def get_def(term)
|
|
24
|
+
# URI Encode
|
|
25
|
+
term = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
|
26
|
+
|
|
27
|
+
# Check if it's not defined.
|
|
28
|
+
if Cinch::Toolbox.get_html_element(ud_url(term), '#not_defined_yet')
|
|
29
|
+
return "Urban Dictionary ∴ #{term}: No definition available."
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Get the def
|
|
33
|
+
ud_def(term)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def ud_def(term)
|
|
37
|
+
# Grab the element
|
|
38
|
+
result = Cinch::Toolbox.get_html_element(ud_url(term), '.meaning')
|
|
39
|
+
|
|
40
|
+
result.gsub!(/[\n\r]/, ' - ')
|
|
41
|
+
|
|
42
|
+
# Make sure it's not terribly long
|
|
43
|
+
result = Cinch::Toolbox.truncate(result, 250)
|
|
44
|
+
url = Cinch::Toolbox.shorten(ud_url(term))
|
|
45
|
+
|
|
46
|
+
debug result
|
|
47
|
+
"Urban Dictionary ∴ #{term}: #{result} [#{url}]"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def ud_url(term)
|
|
51
|
+
"http://www.urbandictionary.com/define.php?term=#{term}"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cinch-urbandict
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|
|
@@ -138,7 +138,7 @@ files:
|
|
|
138
138
|
- Rakefile
|
|
139
139
|
- cinch-urbandict.gemspec
|
|
140
140
|
- lib/cinch-urbandict.rb
|
|
141
|
-
- lib/cinch/plugins/urbandict
|
|
141
|
+
- lib/cinch/plugins/urbandict.rb
|
|
142
142
|
- lib/cinch/plugins/urbandict/version.rb
|
|
143
143
|
- spec/cinch-urbandict_spec.rb
|
|
144
144
|
- spec/spec_helper.rb
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
require 'cinch'
|
|
3
|
-
require 'cinch/cooldown'
|
|
4
|
-
require 'cinch/toolbox'
|
|
5
|
-
|
|
6
|
-
module Cinch::Plugins
|
|
7
|
-
class UrbanDict
|
|
8
|
-
include Cinch::Plugin
|
|
9
|
-
|
|
10
|
-
enforce_cooldown
|
|
11
|
-
|
|
12
|
-
self.help = "Use .ud <term> to see the Urban Dictionary definition for that term."
|
|
13
|
-
|
|
14
|
-
match /ud (.*)/
|
|
15
|
-
|
|
16
|
-
def execute(m, term)
|
|
17
|
-
m.reply get_def(term), true
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def get_def(term)
|
|
23
|
-
# URI Encode
|
|
24
|
-
term = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
|
25
|
-
|
|
26
|
-
url = "http://www.urbandictionary.com/define.php?term=#{term}"
|
|
27
|
-
|
|
28
|
-
if Cinch::Toolbox.get_html_element(url, '#not_defined_yet')
|
|
29
|
-
return "Urban Dictionary ∴ #{term}: No definition available."
|
|
30
|
-
else
|
|
31
|
-
# Grab the element
|
|
32
|
-
result = Cinch::Toolbox.get_html_element(url, '.definition')
|
|
33
|
-
|
|
34
|
-
result.gsub!(/[\n\r]/, ' - ')
|
|
35
|
-
|
|
36
|
-
#Make sure it's not terribly long
|
|
37
|
-
result = Cinch::Toolbox.truncate(result, 250)
|
|
38
|
-
url = Cinch::Toolbox.shorten(url)
|
|
39
|
-
|
|
40
|
-
return "Urban Dictionary ∴ #{term}: #{result} [#{url}]"
|
|
41
|
-
end
|
|
42
|
-
rescue NoMethodError
|
|
43
|
-
debug "Caught a NoMethodError looking up #{term}"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|