Class: SSCBot::User::MessageSender
- Inherits:
-
Object
- Object
- SSCBot::User::MessageSender
- Extended by:
- AttrBool::Ext
- Defined in:
- lib/ssc.bot/user/message_sender.rb
Overview
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_ESCAPE_STR =
'.'
- DEFAULT_FLOOD_COUNT =
8
- DEFAULT_FLOOD_MIN_SLEEP =
0.001
- DEFAULT_FLOOD_SECS =
6
- MM_TICKNAME =
Message Macros
-
In order of F1 Help box.
-
'%tickname'
- MM_SELFNAME =
'%selfname'
- MM_SQUAD =
'%squad'
- MM_FREQ =
'%freq'
- MM_BOUNTY =
'%bounty'
- MM_FLAGS =
'%flags'
- MM_ENERGY =
'%energy'
- MM_KILLER =
'%killer'
- MM_KILLED =
'%killed'
- MM_COORD =
'%coord'
- MM_AREA =
'%area'
- MM_RED =
'%red'
- MM_REDNAME =
'%redname'
- MM_REDBOUNTY =
'%redbounty'
- MM_REDFLAGS =
'%redflags'
Instance Attribute Summary collapse
- #escape_str ⇒ Object
- #flood_count ⇒ Object
- #flood_min_sleep ⇒ Object
- #flood_secs ⇒ Object
- #message_count ⇒ Object readonly
- #message_time ⇒ Object readonly
Instance Method Summary collapse
- #escape_pub(message, escape_percent: @escape_percent, escape_space: @escape_space, escape_str: @escape_str, staff: @staff) ⇒ Object
-
#initialize(escape_percent: false, escape_space: true, escape_str: DEFAULT_ESCAPE_STR, flood_count: DEFAULT_FLOOD_COUNT, flood_min_sleep: DEFAULT_FLOOD_MIN_SLEEP, flood_secs: DEFAULT_FLOOD_SECS, staff: false) ⇒ MessageSender
constructor
A new instance of MessageSender.
- #prevent_flood ⇒ Object
- #put(message) ⇒ Object
- #put_or_type(message) ⇒ Object
- #send(message) ⇒ Object
- #send_chat(message) ⇒ Object
- #send_chat_to(channel, message) ⇒ Object
- #send_freq(message) ⇒ Object
- #send_freq_eq(freq) ⇒ Object
- #send_message ⇒ Object
- #send_or_types(message) ⇒ Object
- #send_or_types_safe(message) ⇒ Object
- #send_private(message) ⇒ Object
- #send_private_to(name, message) ⇒ Object
- #send_private_to_last(message, last = 1) ⇒ Object
- #send_pub(message, **kargs) ⇒ Object
- #send_q_chat ⇒ Object
- #send_q_chat_eq(*names) ⇒ Object
- #send_q_enter ⇒ Object
- #send_q_find(player) ⇒ Object
- #send_q_kill ⇒ Object
- #send_q_leave ⇒ Object
- #send_q_lines ⇒ Object
- #send_q_lines_eq(lines) ⇒ Object
- #send_q_loadmacro(filename) ⇒ Object
- #send_q_log ⇒ Object
- #send_q_log_to(filename) ⇒ Object
- #send_q_logbuffer ⇒ Object
- #send_q_logbuffer_to(filename) ⇒ Object
- #send_q_namelen ⇒ Object
- #send_q_namelen_eq(namelen) ⇒ Object
- #send_q_savemacro(filename) ⇒ Object
- #send_q_spec ⇒ Object
- #send_q_team ⇒ Object
- #send_safe(message) ⇒ Object
- #send_squad(message) ⇒ Object
- #send_squad_to(squad, message) ⇒ Object
- #send_team(message) ⇒ Object
- #send_team2(message) ⇒ Object
- #type(message) ⇒ Object
- #types(message) ⇒ Object
- #types_safe(message) ⇒ Object
Constructor Details
#initialize(escape_percent: false, escape_space: true, escape_str: DEFAULT_ESCAPE_STR, flood_count: DEFAULT_FLOOD_COUNT, flood_min_sleep: DEFAULT_FLOOD_MIN_SLEEP, flood_secs: DEFAULT_FLOOD_SECS, staff: false) ⇒ MessageSender
Returns a new instance of MessageSender.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ssc.bot/user/message_sender.rb', line 82 def initialize(escape_percent: false,escape_space: true,escape_str: DEFAULT_ESCAPE_STR, flood_count: DEFAULT_FLOOD_COUNT,flood_min_sleep: DEFAULT_FLOOD_MIN_SLEEP, flood_secs: DEFAULT_FLOOD_SECS,staff: false) super() @escape_percent = escape_percent @escape_space = escape_space @escape_str = escape_str @flood_count = flood_count @flood_min_sleep = flood_min_sleep @flood_secs = flood_secs @message_count = 0 @message_time = Time.now @staff = staff end |
Instance Attribute Details
#escape_str ⇒ Object
62 63 64 |
# File 'lib/ssc.bot/user/message_sender.rb', line 62 def escape_str @escape_str end |
#flood_count ⇒ Object
63 64 65 |
# File 'lib/ssc.bot/user/message_sender.rb', line 63 def flood_count @flood_count end |
#flood_min_sleep ⇒ Object
64 65 66 |
# File 'lib/ssc.bot/user/message_sender.rb', line 64 def flood_min_sleep @flood_min_sleep end |
#flood_secs ⇒ Object
65 66 67 |
# File 'lib/ssc.bot/user/message_sender.rb', line 65 def flood_secs @flood_secs end |
#message_count ⇒ Object (readonly)
66 67 68 |
# File 'lib/ssc.bot/user/message_sender.rb', line 66 def @message_count end |
#message_time ⇒ Object (readonly)
67 68 69 |
# File 'lib/ssc.bot/user/message_sender.rb', line 67 def @message_time end |
Instance Method Details
#escape_pub(message, escape_percent: @escape_percent, escape_space: @escape_space, escape_str: @escape_str, staff: @staff) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ssc.bot/user/message_sender.rb', line 98 def escape_pub(,escape_percent: @escape_percent,escape_space: @escape_space, escape_str: @escape_str,staff: @staff) if escape_percent = .gsub('%','%%') end escape = false case [0] when '#' escape = true else if escape_space && [0] =~ /[[:space:]]/ escape = true else = Util.u_lstrip() case [0] when ':' if .index(':',1) escape = true end when '/',"'",'"',';','=' escape = true when '?' if [1] =~ /[[:alpha:]]/ escape = true end when '*','-' escape = true if staff end end end if escape = "#{escape_str}#{}" end return end |
#prevent_flood ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ssc.bot/user/message_sender.rb', line 139 def prevent_flood @message_count += 1 if @message_count >= @flood_count diff_time = Time.now - @message_time if diff_time <= @flood_secs sleep_secs = (@flood_secs - diff_time).round(4) + 0.001 sleep_secs = @flood_min_sleep if sleep_secs < @flood_min_sleep else sleep_secs = @flood_min_sleep end sleep(sleep_secs) @message_count = 0 end @message_time = Time.now end |
#put(message) ⇒ Object
70 71 72 |
# File 'lib/ssc.bot/user/message_sender.rb', line 70 def put() raise AbstractMethodError,__method__ end |
#put_or_type(message) ⇒ Object
160 161 162 |
# File 'lib/ssc.bot/user/message_sender.rb', line 160 def put_or_type() put() end |
#send(message) ⇒ Object
164 165 166 167 |
# File 'lib/ssc.bot/user/message_sender.rb', line 164 def send() put() end |
#send_chat(message) ⇒ Object
193 194 195 |
# File 'lib/ssc.bot/user/message_sender.rb', line 193 def send_chat() send_safe(";#{}") end |
#send_chat_to(channel, message) ⇒ Object
197 198 199 |
# File 'lib/ssc.bot/user/message_sender.rb', line 197 def send_chat_to(channel,) send_safe(";#{channel};#{}") end |
#send_freq(message) ⇒ Object
201 202 203 |
# File 'lib/ssc.bot/user/message_sender.rb', line 201 def send_freq() send_safe(%Q("#{})) end |
#send_freq_eq(freq) ⇒ Object
205 206 207 |
# File 'lib/ssc.bot/user/message_sender.rb', line 205 def send_freq_eq(freq) send_safe("=#{freq}") end |
#send_message ⇒ Object
74 75 76 |
# File 'lib/ssc.bot/user/message_sender.rb', line 74 def raise AbstractMethodError,__method__ end |
#send_or_types(message) ⇒ Object
169 170 171 |
# File 'lib/ssc.bot/user/message_sender.rb', line 169 def send_or_types() send() end |
#send_or_types_safe(message) ⇒ Object
173 174 175 176 |
# File 'lib/ssc.bot/user/message_sender.rb', line 173 def send_or_types_safe() send_or_types() prevent_flood end |
#send_private(message) ⇒ Object
209 210 211 |
# File 'lib/ssc.bot/user/message_sender.rb', line 209 def send_private() send_safe("/#{}") end |
#send_private_to(name, message) ⇒ Object
213 214 215 |
# File 'lib/ssc.bot/user/message_sender.rb', line 213 def send_private_to(name,) send_safe(":#{name}:#{}") end |
#send_private_to_last(message, last = 1) ⇒ Object
217 218 219 220 221 222 223 224 225 |
# File 'lib/ssc.bot/user/message_sender.rb', line 217 def send_private_to_last(,last=1) put_or_type('::') while (last -= 1) > 0 put_or_type(':') end send_safe() end |
#send_pub(message, **kargs) ⇒ Object
227 228 229 |
# File 'lib/ssc.bot/user/message_sender.rb', line 227 def send_pub(,**kargs) send_safe(escape_pub(,**kargs)) end |
#send_q_chat ⇒ Object
231 232 233 |
# File 'lib/ssc.bot/user/message_sender.rb', line 231 def send_q_chat send_safe('?chat') end |
#send_q_chat_eq(*names) ⇒ Object
235 236 237 |
# File 'lib/ssc.bot/user/message_sender.rb', line 235 def send_q_chat_eq(*names) send_safe("?chat=#{names.join(',')}") end |
#send_q_enter ⇒ Object
239 240 241 |
# File 'lib/ssc.bot/user/message_sender.rb', line 239 def send_q_enter send_safe('?enter') end |
#send_q_find(player) ⇒ Object
243 244 245 |
# File 'lib/ssc.bot/user/message_sender.rb', line 243 def send_q_find(player) send_safe("?find #{player}") end |
#send_q_kill ⇒ Object
247 248 249 |
# File 'lib/ssc.bot/user/message_sender.rb', line 247 def send_q_kill send_safe('?kill') end |
#send_q_leave ⇒ Object
251 252 253 |
# File 'lib/ssc.bot/user/message_sender.rb', line 251 def send_q_leave send_safe('?leave') end |
#send_q_lines ⇒ Object
283 284 285 |
# File 'lib/ssc.bot/user/message_sender.rb', line 283 def send_q_lines send_safe('?lines') end |
#send_q_lines_eq(lines) ⇒ Object
287 288 289 |
# File 'lib/ssc.bot/user/message_sender.rb', line 287 def send_q_lines_eq(lines) send_safe("?lines=#{lines}") end |
#send_q_loadmacro(filename) ⇒ Object
255 256 257 |
# File 'lib/ssc.bot/user/message_sender.rb', line 255 def send_q_loadmacro(filename) send_safe("?loadmacro #{filename}") end |
#send_q_log ⇒ Object
259 260 261 |
# File 'lib/ssc.bot/user/message_sender.rb', line 259 def send_q_log send_safe('?log') end |
#send_q_log_to(filename) ⇒ Object
263 264 265 |
# File 'lib/ssc.bot/user/message_sender.rb', line 263 def send_q_log_to(filename) send_safe("?log #{filename}") end |
#send_q_logbuffer ⇒ Object
267 268 269 |
# File 'lib/ssc.bot/user/message_sender.rb', line 267 def send_q_logbuffer send_safe('?logbuffer') end |
#send_q_logbuffer_to(filename) ⇒ Object
271 272 273 |
# File 'lib/ssc.bot/user/message_sender.rb', line 271 def send_q_logbuffer_to(filename) send_safe("?logbuffer #{filename}") end |
#send_q_namelen ⇒ Object
275 276 277 |
# File 'lib/ssc.bot/user/message_sender.rb', line 275 def send_q_namelen send_safe('?namelen') end |
#send_q_namelen_eq(namelen) ⇒ Object
279 280 281 |
# File 'lib/ssc.bot/user/message_sender.rb', line 279 def send_q_namelen_eq(namelen) send_safe("?namelen=#{namelen}") end |
#send_q_savemacro(filename) ⇒ Object
291 292 293 |
# File 'lib/ssc.bot/user/message_sender.rb', line 291 def send_q_savemacro(filename) send_safe("?savemacro #{filename}") end |
#send_q_spec ⇒ Object
295 296 297 |
# File 'lib/ssc.bot/user/message_sender.rb', line 295 def send_q_spec send_safe('?spec') end |
#send_q_team ⇒ Object
299 300 301 |
# File 'lib/ssc.bot/user/message_sender.rb', line 299 def send_q_team send_safe('?team') end |
#send_safe(message) ⇒ Object
178 179 180 181 |
# File 'lib/ssc.bot/user/message_sender.rb', line 178 def send_safe() send() prevent_flood end |
#send_squad(message) ⇒ Object
303 304 305 |
# File 'lib/ssc.bot/user/message_sender.rb', line 303 def send_squad() send_safe("##{}") end |
#send_squad_to(squad, message) ⇒ Object
307 308 309 |
# File 'lib/ssc.bot/user/message_sender.rb', line 307 def send_squad_to(squad,) send_safe(":##{squad}:#{}") end |
#send_team(message) ⇒ Object
311 312 313 |
# File 'lib/ssc.bot/user/message_sender.rb', line 311 def send_team() send_safe("//#{}") end |
#send_team2(message) ⇒ Object
315 316 317 |
# File 'lib/ssc.bot/user/message_sender.rb', line 315 def send_team2() send_safe("'#{}") end |
#type(message) ⇒ Object
78 79 80 |
# File 'lib/ssc.bot/user/message_sender.rb', line 78 def type() raise AbstractMethodError,__method__ end |
#types(message) ⇒ Object
183 184 185 186 |
# File 'lib/ssc.bot/user/message_sender.rb', line 183 def types() type() end |
#types_safe(message) ⇒ Object
188 189 190 191 |
# File 'lib/ssc.bot/user/message_sender.rb', line 188 def types_safe() types() prevent_flood end |