1
Fork 0
mirror of https://github.com/RGBCube/bonfire.v synced 2025-07-28 14:37:44 +00:00

Better docs

This commit is contained in:
RGBCube 2022-12-05 18:41:23 +03:00
parent aa4e89d066
commit 8de1cb17d7
2 changed files with 8 additions and 6 deletions

View file

@ -4,9 +4,9 @@ import time
const discord_epoch_milliseconds = u64(1420070400000)
// Snowflake is a Discord snowflake ID. It holds the time the
// object was created, the ID of the worker that created it,
// the ID of the process that created it, and a sequence number.
// Snowflake is a Discord ID. It holds the time the object
// was created, the ID of the worker that created it, the
// ID of the process that created it, and a sequence number.
pub type Snowflake = u64
// created_at returns the Time the Snowflake was created at.
@ -29,8 +29,8 @@ pub fn (s Snowflake) process_id() u8 {
return u8((s & 0x1F000) >> 12)
}
// sequence_number returns the sequence number of the Snowflake (For every Snowflake that
// is generated in the process, the sequence number is incremented by 1).
// sequence_number returns the sequence number of the Snowflake (For every Snowflake
// that is generated in the process, the sequence number is incremented by 1.).
[inline]
pub fn (s Snowflake) sequence_number() u16 {
return u16(s & 0xFFF)
@ -44,6 +44,7 @@ fn new_snowflake(unix u64) Snowflake {
// vfmt on
}
// separate_seconds_and_milliseconds separates the seconds and milliseconds from the given milliseconds.
[inline]
fn separate_seconds_and_milliseconds(milliseconds u64) (i64, int) {
return i64(milliseconds / 1000), int(milliseconds % 1000)

View file

@ -6,6 +6,7 @@ import time
pub type Time = time.Time
// TimeFormat is an enum of all possible Discord timestamp formats.
// See https://discord.com/developers/docs/reference#message-formatting-timestamp-styles.
pub enum TimeFormat as u8 {
short_time = u8(`t`) // 21:27
long_time = u8(`T`) // 21:27:42
@ -17,7 +18,7 @@ pub enum TimeFormat as u8 {
}
// format returns a Discord representation of the time in the given format.
// E.g. <t:1670178420:f> for 4 December 2022 21:27.
// E.g. <t:1670178420:f> for TimeFormat.short_date_time ran on a time of 1670178420.
[inline]
pub fn (t Time) format(format TimeFormat) string {
return '<t:${t.unix}:${rune(format)}>'