Skip to content

Instantly share code, notes, and snippets.

@FiveYellowMice
Created February 9, 2017 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiveYellowMice/31e48b35d99a095f27c29d960f2b7f8c to your computer and use it in GitHub Desktop.
Save FiveYellowMice/31e48b35d99a095f27c29d960f2b7f8c to your computer and use it in GitHub Desktop.
IDCChicories plugin for HoroBot2
# frozen_string_literal: true
require 'active_support/core_ext/numeric/time'
class HoroBot2::Plugins::IDCChicories < HoroBot2::Plugins::Base
RECEIVE_ONLY_WHEN_MATCH = /(?<!\w)(?:线路|骨干网|教育网|数据中心|線路|骨幹網|教育網|數據中心|IDC|BGP|OVH|AnyCast|NTT|QoS|PCCW|IMS|TEA|Cogent|[a-z]{2,3}NET|GRX|IPX|TFN|CN2|CERNET|[a-z]{2}IX|[EG]PON)(?!\w)/i
MESSAGE = "\u{1f31a} IDC 大佬们又要开始谈笑风生了。"
def initialize(*args)
super(*args)
@last_msgs = {}
@last_waves = {}
end
def receive(message)
time_now = Time.now
last_msg = @last_msgs[message.group] || 0
last_wave = @last_waves[message.group] || 0
if time_now - last_wave <= 30.minutes.to_i
@last_waves[message.group] = time_now
else
if time_now - last_msg <= 3.minutes.to_i
message.group.send_text MESSAGE
@last_waves[message.group] = time_now
end
@last_msgs[message.group] = time_now
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment