cinch-yaml-keywords 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2012 Michal Papis
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Cinch YAML keywords plugin
2
+
3
+ A Cinch plugin to define keywords and display description when keyword matches, keywords are saved in yaml file for persistence.
@@ -0,0 +1,67 @@
1
+ require 'yaml'
2
+
3
+ module Cinch
4
+ module Plugins
5
+ class YamlKeywords
6
+ include Cinch::Plugin
7
+
8
+ def initialize(*args)
9
+ super
10
+ if File.exist?('keywords.yaml')
11
+ @keywords = YAML.load_file('keywords.yaml')
12
+ else
13
+ @keywords = {}
14
+ end
15
+ end
16
+
17
+ match(/keywords/, method: :keywords)
18
+ def keywords(m)
19
+ if @keywords.size > 0
20
+ m.reply "Keywords start:"
21
+ @keywords.each{|k,v| m.reply "'#{k}': '#{v}'." }
22
+ m.reply "Keywords end."
23
+ else
24
+ m.reply "No keywords defined yet."
25
+ end
26
+ end
27
+
28
+ match(/keyword (\S+) (.+)$/, method: :keyword_define)
29
+ match(/keyword '(.*)' (.+)$/, method: :keyword_define)
30
+ match(/keyword "(.*)" (.+)$/, method: :keyword_define)
31
+ def keyword_define(m, keyword, definition)
32
+ if @keywords[keyword]
33
+ m.reply "Redefining '#{keyword}' from: '#{@keywords[keyword]}' to: '#{definition}'."
34
+ else
35
+ m.reply "Defining '#{keyword}' with: '#{definition}'."
36
+ end
37
+ @keywords[keyword] = definition
38
+ update_store
39
+ end
40
+
41
+ match(/keyword (\S+)$/, method: :keyword_check)
42
+ def keyword_check(m, keyword)
43
+ if @keywords[keyword]
44
+ m.reply "'#{keyword}' is defined as: '#{@keywords[keyword]}'."
45
+ else
46
+ m.reply "'#{keyword}' is not defined."
47
+ end
48
+ end
49
+
50
+ listen_to :channel
51
+ def listen(m)
52
+ if keyword = @keywords.keys.find{|k| Regexp.new(k).match(m.message) }
53
+ then
54
+ m.reply @keywords[keyword]
55
+ end
56
+ end
57
+
58
+ def update_store
59
+ synchronize(:update) do
60
+ File.open('keywords.yaml', 'w') do |fh|
61
+ YAML.dump(@keywords, fh)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-yaml-keywords
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michal Papis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ description: A Cinch plugin to define keywords and display description when keyword
31
+ matches, keywords are saved in yaml file for persistence.
32
+ email:
33
+ - mpapis@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - LICENSE
39
+ - README.md
40
+ - lib/cinch/plugins/yamlkeywords.rb
41
+ homepage: https://github.com/mpapis/cinch-yaml-keywords
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.9.1
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.24
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A Cinch plugin to define keywords and display description when keyword matches,
65
+ keywords are saved in yaml file for persistence.
66
+ test_files: []