Remove writer role if a channel member did not write anything in the past 24
hours:
const urbit = require("urbit_thread");
function unix_seconds_to_urbit(seconds) {
const seconds = BigInt(Math.floor(seconds));
return (seconds + 0x8000000cce9e0d80n) * (1n << 64n);
}
module.exports = () => {
const nest = 'chat/~sampel-palnet/general';
const now_seconds = Math.floor(Date.now() / 1000);
const yesterday_seconds = now_seconds - 24 * 60 * 60;
const yesterday_urbit = unix_seconds_to_urbit(yesterday_seconds);
let num = 10
let messages = urbit.tlon.get_channel_messages(nest, num);
while ( BigInt(messages[0].key) > yesterday_urbit ) {
num = num * 2;
messages = urbit.tlon.get_channel_messages(nest, num);
}
const users = urbit.tlon.get_channel_members(nest);
let users_set = new Set(users);
for (const value of messages) {
if ( BigInt(value.key) < yesterday_urbit ) continue;
users_set.delete(value.message.author);
}
for (const silent of users_set) {
urbit.tlon.remove_role(silent, 'writer');
}
}