Skip to content

Instantly share code, notes, and snippets.

@dozreg-toplud
Created December 18, 2025 16:41
Show Gist options
  • Select an option

  • Save dozreg-toplud/5ab0efe322c95e4a0b41d4ac69cdd606 to your computer and use it in GitHub Desktop.

Select an option

Save dozreg-toplud/5ab0efe322c95e4a0b41d4ac69cdd606 to your computer and use it in GitHub Desktop.

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');
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment