This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Slash Nephy
committed
Aug 26, 2018
1 parent
061e6f3
commit 949bf8f
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package jp.nephy.tweetstorm.task | ||
|
||
import jp.nephy.penicillin.request.allIds | ||
import jp.nephy.penicillin.request.allUsers | ||
import jp.nephy.tweetstorm.TaskManager | ||
import java.util.concurrent.TimeUnit | ||
|
||
class SyncList(override val manager: TaskManager): RegularTask(5, TimeUnit.MINUTES) { | ||
override fun run() { | ||
val followingIds = if (manager.account.syncListIncludeSelf) { | ||
manager.twitter.friend.listIds().complete().untilLast().allIds + manager.account.id | ||
} else { | ||
manager.twitter.friend.listIds().complete().untilLast().allIds | ||
} | ||
|
||
if (followingIds.size > 3000) { | ||
logger.warn { "This list exceeded 3000 members limit." } | ||
return | ||
} | ||
|
||
val listMemberIds = manager.twitter.list.members(listId = manager.account.listId).complete().untilLast().allUsers.map { it.id } | ||
|
||
val willBeRemoved = listMemberIds.filter { it !in followingIds } | ||
if (willBeRemoved.isNotEmpty()) { | ||
willBeRemoved.chunked(100).forEach { | ||
manager.twitter.list.removeMembers(listId = manager.account.listId, userIds = it).queue() | ||
} | ||
logger.debug { "Removing ${willBeRemoved.size} user(s)." } | ||
} | ||
|
||
val willBeAdded = followingIds.filter { it !in listMemberIds } | ||
if (willBeAdded.isNotEmpty()) { | ||
willBeAdded.chunked(100).forEach { | ||
manager.twitter.list.addMembers(listId = manager.account.listId, userIds = it).queue() | ||
} | ||
logger.debug { "Adding ${willBeAdded.size} user(s)." } | ||
} | ||
} | ||
} |