Discord.js: Add arguments to SnowflakeUtil to generate timestamp-specified snowflake

Created on 9 Oct 2017  Â·  2Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
I think this function will be helpful such as tracing backlogs of a specific server by using fetchMessages(). The code using now generates snowflake only for the current timestamp Date.now()

Include a reproducible code sample here, if possible:
discord.js/src/util/Snowflake.js:
I rewrited some parts to make the generate function more "dynamic":

  static generate(time = null) {
    if (INCREMENT >= 4095) INCREMENT = 0;
    var timestamp = + new Date(); // Date to Timestamp conversion
    if (time !== null) {
        timestamp = Date.parse(time) // Test if time string is valid
        if (!timestamp) return false;
    }
    const BINARY = `${pad((timestamp - EPOCH).toString(2), 42)}0000100000${pad((INCREMENT++).toString(2), 12)}`;
    return Long.fromString(BINARY, 2).toString();
  }

The code will now return a snowflake with the corresponding timestamp value.

Further details:

  • discord.js version: 11.2.1
  • node.js version: 8.5.0
  • Operating system: Raspbian w/ kernel 4.9.35-v7+
  • Priority this issue should have – please be realistic and elaborate if possible:
    This could be a enhancement function and may help users with the needs of data investigation over chatlogs.

  • [ ] I found this issue while running code on a __user account__
  • [ ] I have also tested the issue on latest master, commit hash:
utility discussion enhancement

Most helpful comment

shouldn't you just PR that "feature" instead opening an issue :thinking:

All 2 comments

shouldn't you just PR that "feature" instead opening an issue :thinking:

Sorry but I am a newbie of github, I will try that way.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

shukriadams picture shukriadams  Â·  3Comments

LLamaFTL picture LLamaFTL  Â·  3Comments