grinch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +1 -0
  3. data/LICENSE +22 -0
  4. data/README.md +180 -0
  5. data/docs/bot_options.md +454 -0
  6. data/docs/changes.md +541 -0
  7. data/docs/common_mistakes.md +60 -0
  8. data/docs/common_tasks.md +57 -0
  9. data/docs/encodings.md +69 -0
  10. data/docs/events.md +273 -0
  11. data/docs/getting_started.md +184 -0
  12. data/docs/logging.md +90 -0
  13. data/docs/migrating.md +267 -0
  14. data/docs/plugins.md +4 -0
  15. data/docs/readme.md +20 -0
  16. data/examples/basic/autovoice.rb +32 -0
  17. data/examples/basic/google.rb +35 -0
  18. data/examples/basic/hello.rb +15 -0
  19. data/examples/basic/join_part.rb +34 -0
  20. data/examples/basic/memo.rb +39 -0
  21. data/examples/basic/msg.rb +16 -0
  22. data/examples/basic/seen.rb +36 -0
  23. data/examples/basic/urban_dict.rb +35 -0
  24. data/examples/basic/url_shorten.rb +35 -0
  25. data/examples/plugins/autovoice.rb +37 -0
  26. data/examples/plugins/custom_prefix.rb +23 -0
  27. data/examples/plugins/dice_roll.rb +38 -0
  28. data/examples/plugins/google.rb +36 -0
  29. data/examples/plugins/hello.rb +22 -0
  30. data/examples/plugins/hooks.rb +36 -0
  31. data/examples/plugins/join_part.rb +42 -0
  32. data/examples/plugins/lambdas.rb +35 -0
  33. data/examples/plugins/last_nick.rb +24 -0
  34. data/examples/plugins/msg.rb +22 -0
  35. data/examples/plugins/multiple_matches.rb +32 -0
  36. data/examples/plugins/own_events.rb +37 -0
  37. data/examples/plugins/seen.rb +45 -0
  38. data/examples/plugins/timer.rb +22 -0
  39. data/examples/plugins/url_shorten.rb +33 -0
  40. data/lib/cinch.rb +5 -0
  41. data/lib/cinch/ban.rb +50 -0
  42. data/lib/cinch/bot.rb +479 -0
  43. data/lib/cinch/cached_list.rb +19 -0
  44. data/lib/cinch/callback.rb +20 -0
  45. data/lib/cinch/channel.rb +463 -0
  46. data/lib/cinch/channel_list.rb +29 -0
  47. data/lib/cinch/configuration.rb +73 -0
  48. data/lib/cinch/configuration/bot.rb +48 -0
  49. data/lib/cinch/configuration/dcc.rb +16 -0
  50. data/lib/cinch/configuration/plugins.rb +41 -0
  51. data/lib/cinch/configuration/sasl.rb +19 -0
  52. data/lib/cinch/configuration/ssl.rb +19 -0
  53. data/lib/cinch/configuration/timeouts.rb +14 -0
  54. data/lib/cinch/constants.rb +533 -0
  55. data/lib/cinch/dcc.rb +12 -0
  56. data/lib/cinch/dcc/dccable_object.rb +37 -0
  57. data/lib/cinch/dcc/incoming.rb +1 -0
  58. data/lib/cinch/dcc/incoming/send.rb +147 -0
  59. data/lib/cinch/dcc/outgoing.rb +1 -0
  60. data/lib/cinch/dcc/outgoing/send.rb +122 -0
  61. data/lib/cinch/exceptions.rb +46 -0
  62. data/lib/cinch/formatting.rb +125 -0
  63. data/lib/cinch/handler.rb +118 -0
  64. data/lib/cinch/handler_list.rb +90 -0
  65. data/lib/cinch/helpers.rb +231 -0
  66. data/lib/cinch/irc.rb +924 -0
  67. data/lib/cinch/isupport.rb +98 -0
  68. data/lib/cinch/log_filter.rb +21 -0
  69. data/lib/cinch/logger.rb +168 -0
  70. data/lib/cinch/logger/formatted_logger.rb +97 -0
  71. data/lib/cinch/logger/zcbot_logger.rb +22 -0
  72. data/lib/cinch/logger_list.rb +85 -0
  73. data/lib/cinch/mask.rb +69 -0
  74. data/lib/cinch/message.rb +392 -0
  75. data/lib/cinch/message_queue.rb +107 -0
  76. data/lib/cinch/mode_parser.rb +76 -0
  77. data/lib/cinch/network.rb +104 -0
  78. data/lib/cinch/open_ended_queue.rb +26 -0
  79. data/lib/cinch/pattern.rb +65 -0
  80. data/lib/cinch/plugin.rb +515 -0
  81. data/lib/cinch/plugin_list.rb +38 -0
  82. data/lib/cinch/rubyext/float.rb +3 -0
  83. data/lib/cinch/rubyext/module.rb +26 -0
  84. data/lib/cinch/rubyext/string.rb +33 -0
  85. data/lib/cinch/sasl.rb +34 -0
  86. data/lib/cinch/sasl/dh_blowfish.rb +71 -0
  87. data/lib/cinch/sasl/diffie_hellman.rb +47 -0
  88. data/lib/cinch/sasl/mechanism.rb +6 -0
  89. data/lib/cinch/sasl/plain.rb +26 -0
  90. data/lib/cinch/syncable.rb +83 -0
  91. data/lib/cinch/target.rb +199 -0
  92. data/lib/cinch/timer.rb +145 -0
  93. data/lib/cinch/user.rb +488 -0
  94. data/lib/cinch/user_list.rb +87 -0
  95. data/lib/cinch/utilities/deprecation.rb +16 -0
  96. data/lib/cinch/utilities/encoding.rb +37 -0
  97. data/lib/cinch/utilities/kernel.rb +13 -0
  98. data/lib/cinch/version.rb +4 -0
  99. metadata +140 -0
@@ -0,0 +1,87 @@
1
+ require "cinch/cached_list"
2
+
3
+ module Cinch
4
+ # @since 2.0.0
5
+ # @version 1.1.0
6
+ # @note In prior versions, this class was called UserManager
7
+ class UserList < CachedList
8
+ # Finds or creates a user.
9
+ # @overload find_ensured(nick)
10
+ # Finds or creates a user based on their nick.
11
+ #
12
+ # @param [String] nick The user's nickname
13
+ # @return [User]
14
+ # @overload find_ensured(user, nick, host)
15
+ # Finds or creates a user based on their nick but already
16
+ # setting user and host.
17
+ #
18
+ # @param [String] user The username
19
+ # @param [String] nick The nickname
20
+ # @param [String] host The user's hostname
21
+ # @return [User]
22
+ # @return [User]
23
+ # @see Bot#User
24
+ def find_ensured(*args)
25
+ user, host = nil, nil
26
+ case args.size
27
+ when 1
28
+ nick = args.first
29
+ bargs = [nick]
30
+ when 3
31
+ nick = args[1]
32
+ bargs = args
33
+ user, _, host = bargs
34
+ else
35
+ raise ArgumentError
36
+ end
37
+
38
+ if nick == @bot.nick
39
+ user_obj = @bot
40
+ end
41
+
42
+ downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
43
+ @mutex.synchronize do
44
+ if user_obj.nil?
45
+ user_obj = @cache[downcased_nick] ||= User.new(*bargs, @bot)
46
+ end
47
+ if user && host
48
+ # Explicitly set user and host whenever we request a User
49
+ # object to update them on e.g. JOIN.
50
+ user_obj.sync(:user, user, true)
51
+ user_obj.sync(:host, host, true)
52
+ end
53
+ user_obj
54
+ end
55
+ end
56
+
57
+ # Finds a user.
58
+ #
59
+ # @param [String] nick nick of a user
60
+ # @return [User, nil]
61
+ def find(nick)
62
+ if nick == @bot.nick
63
+ return @bot
64
+ end
65
+
66
+ downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
67
+ @mutex.synchronize do
68
+ return @cache[downcased_nick]
69
+ end
70
+ end
71
+
72
+ # @api private
73
+ # @return [void]
74
+ def update_nick(user)
75
+ @mutex.synchronize do
76
+ @cache.delete user.last_nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
77
+ @cache[user.nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])] = user
78
+ end
79
+ end
80
+
81
+ # @api private
82
+ # @return [void]
83
+ def delete(user)
84
+ @cache.delete_if {|n, u| u == user }
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,16 @@
1
+ module Cinch
2
+ module Utilities
3
+ # @since 2.0.0
4
+ # @api private
5
+ module Deprecation
6
+ def self.print_deprecation(version, method, instead = nil)
7
+ s = "Deprecation warning: Beginning with version #{version}, #{method} should not be used anymore."
8
+ if instead != nil
9
+ s << " Use #{instead} instead."
10
+ end
11
+ $stderr.puts s
12
+ $stderr.puts caller
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ module Cinch
2
+ module Utilities
3
+ # @since 2.0.0
4
+ # @api private
5
+ module Encoding
6
+ def self.encode_incoming(string, encoding)
7
+ string = string.dup
8
+ if encoding == :irc
9
+ # If incoming text is valid UTF-8, it will be interpreted as
10
+ # such. If it fails validation, a CP1252 -&gt; UTF-8 conversion
11
+ # is performed. This allows you to see non-ASCII from mIRC
12
+ # users (non-UTF-8) and other users sending you UTF-8.
13
+ #
14
+ # (from http://xchat.org/encoding/#hybrid)
15
+ string.force_encoding("UTF-8")
16
+ if !string.valid_encoding?
17
+ string.force_encoding("CP1252").encode!("UTF-8", {:invalid => :replace, :undef => :replace})
18
+ end
19
+ else
20
+ string.force_encoding(encoding).encode!({:invalid => :replace, :undef => :replace})
21
+ string = string.chars.select { |c| c.valid_encoding? }.join
22
+ end
23
+
24
+ return string
25
+ end
26
+
27
+ def self.encode_outgoing(string, encoding)
28
+ string = string.dup
29
+ if encoding == :irc
30
+ encoding = "UTF-8"
31
+ end
32
+
33
+ return string.encode!(encoding, {:invalid => :replace, :undef => :replace}).force_encoding("ASCII-8BIT")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ module Cinch
2
+ module Utilities
3
+ # @since 2.0.0
4
+ # @api private
5
+ module Kernel
6
+ # @return [Object]
7
+ def self.string_to_const(s)
8
+ return s unless s.is_a?(::String)
9
+ s.split("::").inject(Kernel) {|base, name| base.const_get(name) }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Cinch
2
+ # Version of the library
3
+ VERSION = '2.3.1'
4
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grinch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - William Woodruff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple, friendly DSL for creating IRC bots
14
+ email:
15
+ - william@yossarian.net
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".yardopts"
21
+ - LICENSE
22
+ - README.md
23
+ - docs/bot_options.md
24
+ - docs/changes.md
25
+ - docs/common_mistakes.md
26
+ - docs/common_tasks.md
27
+ - docs/encodings.md
28
+ - docs/events.md
29
+ - docs/getting_started.md
30
+ - docs/logging.md
31
+ - docs/migrating.md
32
+ - docs/plugins.md
33
+ - docs/readme.md
34
+ - examples/basic/autovoice.rb
35
+ - examples/basic/google.rb
36
+ - examples/basic/hello.rb
37
+ - examples/basic/join_part.rb
38
+ - examples/basic/memo.rb
39
+ - examples/basic/msg.rb
40
+ - examples/basic/seen.rb
41
+ - examples/basic/urban_dict.rb
42
+ - examples/basic/url_shorten.rb
43
+ - examples/plugins/autovoice.rb
44
+ - examples/plugins/custom_prefix.rb
45
+ - examples/plugins/dice_roll.rb
46
+ - examples/plugins/google.rb
47
+ - examples/plugins/hello.rb
48
+ - examples/plugins/hooks.rb
49
+ - examples/plugins/join_part.rb
50
+ - examples/plugins/lambdas.rb
51
+ - examples/plugins/last_nick.rb
52
+ - examples/plugins/msg.rb
53
+ - examples/plugins/multiple_matches.rb
54
+ - examples/plugins/own_events.rb
55
+ - examples/plugins/seen.rb
56
+ - examples/plugins/timer.rb
57
+ - examples/plugins/url_shorten.rb
58
+ - lib/cinch.rb
59
+ - lib/cinch/ban.rb
60
+ - lib/cinch/bot.rb
61
+ - lib/cinch/cached_list.rb
62
+ - lib/cinch/callback.rb
63
+ - lib/cinch/channel.rb
64
+ - lib/cinch/channel_list.rb
65
+ - lib/cinch/configuration.rb
66
+ - lib/cinch/configuration/bot.rb
67
+ - lib/cinch/configuration/dcc.rb
68
+ - lib/cinch/configuration/plugins.rb
69
+ - lib/cinch/configuration/sasl.rb
70
+ - lib/cinch/configuration/ssl.rb
71
+ - lib/cinch/configuration/timeouts.rb
72
+ - lib/cinch/constants.rb
73
+ - lib/cinch/dcc.rb
74
+ - lib/cinch/dcc/dccable_object.rb
75
+ - lib/cinch/dcc/incoming.rb
76
+ - lib/cinch/dcc/incoming/send.rb
77
+ - lib/cinch/dcc/outgoing.rb
78
+ - lib/cinch/dcc/outgoing/send.rb
79
+ - lib/cinch/exceptions.rb
80
+ - lib/cinch/formatting.rb
81
+ - lib/cinch/handler.rb
82
+ - lib/cinch/handler_list.rb
83
+ - lib/cinch/helpers.rb
84
+ - lib/cinch/irc.rb
85
+ - lib/cinch/isupport.rb
86
+ - lib/cinch/log_filter.rb
87
+ - lib/cinch/logger.rb
88
+ - lib/cinch/logger/formatted_logger.rb
89
+ - lib/cinch/logger/zcbot_logger.rb
90
+ - lib/cinch/logger_list.rb
91
+ - lib/cinch/mask.rb
92
+ - lib/cinch/message.rb
93
+ - lib/cinch/message_queue.rb
94
+ - lib/cinch/mode_parser.rb
95
+ - lib/cinch/network.rb
96
+ - lib/cinch/open_ended_queue.rb
97
+ - lib/cinch/pattern.rb
98
+ - lib/cinch/plugin.rb
99
+ - lib/cinch/plugin_list.rb
100
+ - lib/cinch/rubyext/float.rb
101
+ - lib/cinch/rubyext/module.rb
102
+ - lib/cinch/rubyext/string.rb
103
+ - lib/cinch/sasl.rb
104
+ - lib/cinch/sasl/dh_blowfish.rb
105
+ - lib/cinch/sasl/diffie_hellman.rb
106
+ - lib/cinch/sasl/mechanism.rb
107
+ - lib/cinch/sasl/plain.rb
108
+ - lib/cinch/syncable.rb
109
+ - lib/cinch/target.rb
110
+ - lib/cinch/timer.rb
111
+ - lib/cinch/user.rb
112
+ - lib/cinch/user_list.rb
113
+ - lib/cinch/utilities/deprecation.rb
114
+ - lib/cinch/utilities/encoding.rb
115
+ - lib/cinch/utilities/kernel.rb
116
+ - lib/cinch/version.rb
117
+ homepage:
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '2.4'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.0.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: An IRC Bot Building Framework
140
+ test_files: []