mirror of
https://github.com/RGBCube/bonfire.v
synced 2025-07-28 06:27:44 +00:00
Add examples
This commit is contained in:
parent
a7faaf1085
commit
aa4e89d066
3 changed files with 48 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
<h1>bonfire.v</h1>
|
||||
|
||||
[Docs](https://rgbcube.github.io/docs/bonfire)
|
||||
[Docs](https://rgbcube.github.io/docs/bonfire) | [Examples](https://github.com/RGBCube/bonfire.v/tree/master/examples)
|
||||
|
||||
A Discord API wrapper for the V programming language.
|
||||
|
||||
|
|
30
examples/snowflake.v
Normal file
30
examples/snowflake.v
Normal file
|
@ -0,0 +1,30 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
import rgbcube.bonfire { Snowflake, TimeFormat }
|
||||
|
||||
[noreturn]
|
||||
fn print_help_and_exit1() {
|
||||
println('Usage: <format> <id>')
|
||||
println('Format can be either short_time, long_time, short_date, long_date, short_date_time, long_date_time or relative')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
snowflake := Snowflake(os.args[2].i64() or { print_help_and_exit1() })
|
||||
|
||||
format_str := os.args[1]
|
||||
|
||||
format := match format_str {
|
||||
'short_time' { TimeFormat.short_time }
|
||||
'long_time' { TimeFormat.long_time }
|
||||
'short_date' { TimeFormat.short_date }
|
||||
'long_date' { TimeFormat.long_date }
|
||||
'short_date_time' { TimeFormat.short_date_time }
|
||||
'long_date_time' { TimeFormat.long_date_time }
|
||||
'relative' { TimeFormat.relative }
|
||||
else { print_help_and_exit1() }
|
||||
}
|
||||
|
||||
println(snowflake.format(format))
|
||||
}
|
17
examples/time.v
Normal file
17
examples/time.v
Normal file
|
@ -0,0 +1,17 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
import rgbcube.bonfire { Snowflake }
|
||||
|
||||
fn main() {
|
||||
snowflake := Snowflake(os.args[1] or {
|
||||
println('Usage: <id>')
|
||||
exit(1)
|
||||
})
|
||||
|
||||
println('Snowflake: ${snowflake}')
|
||||
println('- Created at: ${snowflake.created_at()}')
|
||||
println('- Worker ID: ${snowflake.worker_id()}')
|
||||
println('- Process ID: ${snowflake.process_id()}')
|
||||
println('- Sequence number: ${snowflake.sequence_number()}')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue