Does #iceshrimp have a way to delete posts older than some age? It's been a feature I've been hoping for in #firefish for a while but it never happened. Would love if it's available. Even if it is a manual DB update or whatever that'll work.
@pseudoramble not a feature but this plugin should work when modifying some parameters
/// @ 0.2
### {
name: "Old notes cleanup"
version: "0.2"
author: "@Varpie@peculiar.florist"
description: "A plugin to automatically remove old posts."
permissions: ["write:notes"]
config: {
debug: {
type: "boolean"
label: "Enable Debugging"
description: "Write debugging information to the console."
default: no
}
daysToKeep: {
type: "number"
label: "Days to keep"
description: "How many days you want to keep your notes before they are deleted."
default: 90
}
loopTime: {
type: "number"
label: "Loop time"
description: "How often the cleanup operation is repeated (in seconds)."
default: 3600
}
notesToDelete: {
type: "number"
label: "Notes to delete"
description: "How many notes will be loaded on every run of the plugin. A higher nummber allows to load and delete more notes, but it will make the execution of the script slower. Valid values: 1-100."
default: 10
}
}
}
@debug(comment) {
? (Plugin:config.debug = yes) {
$comment <- Arr:join(["🔌 Plugin (Old notes cleanup): " comment])
print(comment)
}
}
@loadNotes() {
#currentTime = Date:now()
// Date:now returns current UNIX time in ms, so we want to divide it by 1000 to have it in seconds, then remove *60 for minutes, *60 for hours, *24 for days
#timeToKeep = ((Math:floor((currentTime / 1000)) - (((Plugin:config.daysToKeep*60)*60)*24))*1000)
// We try to load the current userId from the local storage, to avoid an extra API call for each execution of the plugin
#userId = Mk:load("userId")
? (userId = _) {
debug("User ID not found, fetching from API")
#user = Mk:api("i", {})
Mk:save("userId" user.id)
userId <- user.id
}
// Loads user notes older than the specified time.
#notes = Mk:api("users/notes", NULL)
debug(Arr:join(["Notes: " Json:stringify(notes)]))
notes
}
@cleanup() {
debug("Cleanup started")
#notes = loadNotes()
~~ (#note, notes) {
Mk:api("notes/delete", NULL)
}
}
#execute = Mk:load("execute")
? (execute = _) {
#notes = loadNotes()
execute <- Mk:confirm("Parameters confirmation" Arr:join(["The **Old notes cleanup** plugin will be installed, keeping notes from your last " Core:to_str(Plugin:config.daysToKeep) " days, deleting at most " Core:to_str(Plugin:config.notesToDelete) " notes every " Core:to_str(Plugin:config.loopTime) " seconds (or when Firefish is reloaded).
The initial cleanup will remove " Core:to_str(Arr:len(notes)) " notes."]) "question")
Mk:save("execute" execute)
}
? (execute = yes) {
Async:interval((Plugin:config.loopTime*1000), cleanup, yes)
} . {
Mk:dialog("Information" "The plugin script will not be executed. Please uninstall the **Old notes cleanup** plugin, and update the parameters before you re-install it." "info")
}
Add comment