mirror of
https://github.com/RGBCube/revolt.v
synced 2025-07-27 17:07:45 +00:00
Initial commit
This commit is contained in:
commit
8d35bec77b
11 changed files with 255 additions and 0 deletions
9
.editorconfig
Normal file
9
.editorconfig
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.v]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
7
.gitattributes
vendored
Normal file
7
.gitattributes
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
* text=auto eol=lf
|
||||||
|
*.bat eol=crlf
|
||||||
|
|
||||||
|
**/*.v linguist-language=V
|
||||||
|
**/*.vv linguist-language=V
|
||||||
|
**/*.vsh linguist-language=V
|
||||||
|
**/v.mod linguist-language=V
|
48
.github/workflows/deploy-docs.yml
vendored
Normal file
48
.github/workflows/deploy-docs.yml
vendored
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
name: Deploy Docs
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy-docs:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set Up V
|
||||||
|
uses: vlang/setup-v@v1.1
|
||||||
|
with:
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Checkout Site Repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: RGBCube/rgbcube.github.io
|
||||||
|
path: site
|
||||||
|
|
||||||
|
- name: Generate Docs
|
||||||
|
run: |
|
||||||
|
mv ./src ./revolt.v # For the docs header
|
||||||
|
cp ./README.md ./revolt.v/ # For the README to be included in the docs.
|
||||||
|
v doc -readme -f html -o ./ -m ./revolt.v
|
||||||
|
|
||||||
|
rm -rf ./site/docs/revolt || true
|
||||||
|
mkdir -p ./site/docs/revolt
|
||||||
|
cp -r ./_docs/* ./site/docs/revolt/
|
||||||
|
|
||||||
|
- name: Add Private Key To SSH Agent
|
||||||
|
uses: webfactory/ssh-agent@v0.7.0
|
||||||
|
with:
|
||||||
|
ssh-private-key: ${{ secrets.RGBCUBE_GITHUB_IO_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
- name: Push Docs To GitHub
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
cd site
|
||||||
|
|
||||||
|
git config user.name "GitHub Actions"
|
||||||
|
git config user.email "actions@users.noreply.github.com"
|
||||||
|
|
||||||
|
git add ./
|
||||||
|
git commit -m "Deploy revolt.v docs"
|
||||||
|
git push git@github.com:RGBCube/rgbcube.github.io master
|
20
.github/workflows/test.yml
vendored
Normal file
20
.github/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
name: Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
- pull_request
|
||||||
|
- push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set Up V
|
||||||
|
uses: vlang/setup-v@v1.1
|
||||||
|
with:
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: v test ./
|
20
.github/workflows/verify-formatting.yml
vendored
Normal file
20
.github/workflows/verify-formatting.yml
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
name: Verify Formatting
|
||||||
|
|
||||||
|
on:
|
||||||
|
- pull_request
|
||||||
|
- push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
verify-formatting:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set Up V
|
||||||
|
uses: vlang/setup-v@v1.1
|
||||||
|
with:
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Verify That The Code Is Formatted
|
||||||
|
run: v fmt -verify ./
|
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
main
|
||||||
|
revolt
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
bin/
|
||||||
|
.DS_Store
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.iml
|
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022-present RGBCube
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
57
README.md
Normal file
57
README.md
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|
<h1>revolt.v</h1>
|
||||||
|
|
||||||
|
[Docs](https://rgbcube.github.io/docs/revolt) | [Examples](https://github.com/RGBCube/bonfire.v/tree/master/examples)
|
||||||
|
|
||||||
|
A Revolt.chat API wrapper for the V programming language.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
After doing these, you can use the module in your V programs by importing `rgbcube.revolt`.
|
||||||
|
|
||||||
|
### Via VPM
|
||||||
|
|
||||||
|
```bash
|
||||||
|
v install RGBCube.revolt
|
||||||
|
```
|
||||||
|
|
||||||
|
### Via Git
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/RGBCube/revolt.v ~/.vmodules/rgbcube/revolt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
Here are some examples to get you started:
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
```
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022-present RGBCube
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
```
|
28
src/id_holder.v
Normal file
28
src/id_holder.v
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
module revolt
|
||||||
|
|
||||||
|
import time
|
||||||
|
import encoding.binary
|
||||||
|
import encoding.base32
|
||||||
|
|
||||||
|
const ulid_base32_alphabet = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'.bytes()
|
||||||
|
|
||||||
|
// IdHolder is a holder for ULID. Every Revolt object has an (UL)ID.
|
||||||
|
[noinit]
|
||||||
|
pub struct IdHolder {
|
||||||
|
id string
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: This is broken.
|
||||||
|
|
||||||
|
// created_at returns the creation time of the IdHolder.
|
||||||
|
pub fn (idh IdHolder) created_at() !Time {
|
||||||
|
encoder := base32.new_encoding_with_padding(revolt.ulid_base32_alphabet, base32.no_padding)
|
||||||
|
|
||||||
|
str_10_bytes := idh.id[..10].bytes()
|
||||||
|
u64_bytes := encoder.decode(str_10_bytes) or { return error('invalid ULID') }
|
||||||
|
|
||||||
|
milliseconds_total := dump(binary.big_endian_u64_end(u64_bytes))
|
||||||
|
seconds := i64(milliseconds_total / 1000)
|
||||||
|
microseconds := int(milliseconds_total % 1000) * 1000
|
||||||
|
return time.unix2(seconds, microseconds * 1000)
|
||||||
|
}
|
25
src/time.v
Normal file
25
src/time.v
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
module revolt
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
// Time is a time.Time that can be formatted as a Revolt timestamp.
|
||||||
|
pub type Time = time.Time
|
||||||
|
|
||||||
|
// TimeFormat is an enum of all possible Revolt timestamp formats.
|
||||||
|
// See https://developers.revolt.chat/markdown#timestamps.
|
||||||
|
pub enum TimeFormat as u8 {
|
||||||
|
short_time = u8(`t`) // 21:27
|
||||||
|
long_time = u8(`T`) // 21:27:42
|
||||||
|
short_date = u8(`d`) // 4/12/2022
|
||||||
|
long_date = u8(`D`) // 4 December 2022
|
||||||
|
short_date_time = u8(`f`) // 4 December 2022 21:27
|
||||||
|
long_date_time = u8(`F`) // Sunday, 4 December 2022 21:27
|
||||||
|
relative = u8(`R`) // 2 days ago, Now, etc.
|
||||||
|
}
|
||||||
|
|
||||||
|
// format returns a Revolt representation of the time in the given format.
|
||||||
|
// 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)}>'
|
||||||
|
}
|
8
v.mod
Normal file
8
v.mod
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Module {
|
||||||
|
name: 'revolt'
|
||||||
|
description: 'A Revolt.chat API wrapper for the V programming language.'
|
||||||
|
version: '0.0.1'
|
||||||
|
license: 'MIT'
|
||||||
|
repo_url: 'https://github.com/RGBCube/revolt.v'
|
||||||
|
dependencies: []
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue