Skip to content

Instantly share code, notes, and snippets.

@shibafu528
Forked from firstspring1845/block.rb
Last active May 3, 2019 09:20
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 shibafu528/5971b70a39e591e8cedc to your computer and use it in GitHub Desktop.
Save shibafu528/5971b70a39e591e8cedc to your computer and use it in GitHub Desktop.
ふあすぷ氏のブロックコマンドPluginに、フィルタリングを後付けしてみた
# -*- coding: utf-8 -*-
Plugin.create :block do
UserConfig[:block_update_interval] ||= 15
@blocked_ids = []
@no_retweets_ids = []
@muted_user_ids = []
if Environment::VERSION < [3, 6, 0, 0]
command(:block,
name: 'ブロックする',
condition: Plugin::Command::CanReplyAll,
visible: true,
icon: nil,
role: :timeline) do |opt|
user = opt.messages.first.user
if ::Gtk::Dialog.confirm("@#{user[:idname]}をブロックしますよ、本当にいいんですか?")
if ::Gtk::Dialog.confirm("取り返しが付かないですがよろしいですね?")
(Service.primary.twitter/'blocks/create').json(:screen_name => user[:idname]).next do
@blocked_ids << user[:id]
end
end
end
end
else
defspell(:block_user, :twitter, :twitter_user) do |twitter, user|
(Service.primary.twitter/'blocks/create').json(:screen_name => user[:idname]).next do
@blocked_ids << user[:id]
end
end
command(:block,
name: 'ブロックする',
condition: lambda { |opt|
world, = Plugin.filtering(:world_current, nil)
block_user?(world, opt.messages.first.user)
},
visible: true,
icon: nil,
role: :timeline) do |opt|
world, = Plugin.filtering(:world_current, nil)
next unless world
user = opt.messages.first.user
dialog('ブロックする') {
label '以下のユーザーをブロックしますよ、本当にいいんですか?'
link user
await_input
label '取り返しが付かないですがよろしいですね?'
}.next {
block_user(world, user)
}
end
end
filter_show_filter do |msgs|
msgs = msgs.select do |m|
if UserConfig[:block_filter_blocked] then !@blocked_ids.include?(m.user[:id]) else true end
end.select do |m|
if UserConfig[:block_filter_muted_user] then !@muted_user_ids.include?(m.user[:id]) else true end
end
[msgs]
end
filter_show_filter do |msgs|
msgs = msgs.select do |m|
if m.retweet?
if UserConfig[:block_filter_no_retweets] then !@no_retweets_ids.include?(m.user[:id]) else true end
else
true
end
end
[msgs]
end
def fetch_cursor_api(service, endpoint, cursor, &block)
(service.twitter/endpoint).json(:cursor => cursor).next do |json|
block.call(json) if block_given?
fetch_cursor_api(service, endpoint, cursor) unless json[:next_cursor] == 0
end
end
def update_filter_ids
Service.each do |service|
fetch_cursor_api(service, 'blocks/ids', -1) do |json|
@blocked_ids.concat(json[:ids]).uniq!
end
fetch_cursor_api(service, 'mutes/users/ids', -1) do |json|
@muted_user_ids.concat(json[:ids]).uniq!
end
(service.twitter/'friendships/no_retweets/ids').json({}).next do |json|
@no_retweets_ids.concat(json).uniq!
end
end
Reserver.new(UserConfig[:block_update_interval] * 60) do
update_filter_ids()
end
end
settings "ブロックとフィルタリング" do
adjustment "ブロック・RT非表示・ミュートユーザの取得間隔(分)", :block_update_interval, 1, 60
boolean "ブロック済みユーザをフィルタ", :block_filter_blocked
boolean "ミュート済みユーザをフィルタ", :block_filter_muted_user
boolean "公式WebのRT非表示を反映", :block_filter_no_retweets
end
update_filter_ids()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment