Skip to content

Commit 9a1fd68

Browse files
committed
timestamp
1 parent f6d72d2 commit 9a1fd68

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Advanced tag scripts for [Assyst](https://jacher.io/assyst) bot.
66

77
- [Experiments API](#experiments-api)
88
- [Experiment Rollout](#experiment-rollout)
9+
- [Timestamp](#timestamp)
910

1011
## Experiments API
1112

@@ -43,3 +44,18 @@ Replace the `tag_name` with the name of the tag you want to create here and send
4344
experimentRollout('tag_name');
4445
}
4546
```
47+
48+
## Timestamp
49+
50+
By @Tolga1452
51+
52+
### Setup
53+
54+
Replace the `tag_name` with the name of the tag you want to create here and send the message:
55+
56+
```
57+
-t create tag_name {js:
58+
{download:https://raw.githubusercontent.com/discordexperimenthub/assyst-tags/main/timestamp.js}
59+
timestamp('tag_name');
60+
}
61+
```

experiment-rollout/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async function experimentRollout(command, override = null) { // `override` IS ON
66
let string = message.content.split(`${command} `)[1]?.toLowerCase() ?? '';
77
let [id, subcommand] = string.split(' ');
88

9-
if (!id) return `## Usage\n\`-t ${command} <feature_id>\`\n\n## Available Feature Ids\n${Object.keys(data).map(id => `\`${id}\``).join(', ')}\n\n### Last Update\n<t:${lastUpdate}:R>\n\n- Script made by \`✨Tolgchu✨#1452\`: <https://github.com/discordexperimenthub/assyst-tags#experiment-rollout>\n- Our Server: https://discord.gg/vK5sZYdaB6`;
9+
if (!id) return `## Usage\n\`-t ${command} <feature_id>\`\n\n## Available Feature Ids\n${Object.keys(data).map(id => `\`${id}\``).join(', ')}\n\n### Last Update\n<t:${lastUpdate}:R>\n\n- Script made by \`✨Tolgchu✨#1452\`: <https://github.com/discordexperimenthub/assyst-tags#experiment-rollout>\n- Our Server: https://discord.gg/experiments`;
1010
if (!data[id]) return `❌ This feature id does not exist. Type **\`-t ${command}\`** to see all available feature ids.`;
1111

1212
let { rate, ranges, experimentType, rolloutType, requirements, priority, notes, timestamp, replacedBy, details } = data[id];

timestamp.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function timestamp(tag) {
2+
let string = message.content.split(`${tag} `)[1]?.toLowerCase() ?? '';
3+
let [command] = string.split(' ');
4+
5+
if (!command) return `## Usage\n\`-t ${tag} <command>\`\n\n## Available Commands\n- **\`now\` -** Get current timestamp.\n- **\`create\` -** Create a timestamp.\n\n- Script made by \`✨Tolgchu✨#1452\`: <https://github.com/discordexperimenthub/assyst-tags#experiment-rollout>\n- Our Server: https://discord.gg/experiments`;
6+
7+
let response = '';
8+
9+
switch (command) {
10+
case 'now':
11+
let milliseconds = Date.now();
12+
let seconds = Math.floor(milliseconds / 1000);
13+
14+
response = `## Current Timestamp\n<t:${seconds}:F>\n- **In Seconds:** ${seconds}\n- **In Milliseconds:** ${milliseconds}\n\n## Discord Timestamp Styles\n- **<t:${seconds}:t>:** \`<t:${seconds}:t>\`\n- **<t:${seconds}:T>:** \`<t:${seconds}:T>\`\n- **<t:${seconds}:d>:** \`<t:${seconds}:d>\`\n- **<t:${seconds}:D>:** \`<t:${seconds}:D>\`\n- **<t:${seconds}:f> (Default):** \`<t:${seconds}:f>\` or \`<t:${seconds}>\`\n- **<t:${seconds}:F>:** \`<t:${seconds}:F>\`\n- **<t:${seconds}:R>:** \`<t:${seconds}:R>\``;
15+
break;
16+
17+
case 'create':
18+
let regex = /^\d{4}-\d{2}-\d{2}(?: \d{2}:\d{2}:\d{2})?(?: [+-]\d{2}:\d{2})?$/
19+
let trydate = string.split(`${command} `)[1];
20+
21+
if (!trydate.match(regex)) return `❌ Please enter a valid date!\n- **Usage:** \`-t ${tag} create <YYYY-MM-DD> [<HH:mm:ss>] [<time_zone>]\`\n**Example:** \`-t ${tag} create 2011-10-10 14:48:00 +09:00\``;
22+
23+
let [date, time, zone] = date.split(' ');
24+
25+
let milliseconds2 = Date.now(`${date}${time ? `T${time}${zone ?? ''}` : ''}`);
26+
let seconds2 = Math.floor(milliseconds / 1000);
27+
28+
response = `## Created Timestamp\n<t:${seconds2}:F>\n- **In Seconds:** ${seconds2}\n- **In Milliseconds:** ${milliseconds2}\n\n## Discord Timestamp Styles\n- **<t:${seconds2}:t>:** \`<t:${seconds2}:t>\`\n- **<t:${seconds2}:T>:** \`<t:${seconds2}:T>\`\n- **<t:${seconds2}:d>:** \`<t:${seconds2}:d>\`\n- **<t:${seconds2}:D>:** \`<t:${seconds2}:D>\`\n- **<t:${seconds2}:f> (Default):** \`<t:${seconds2}:f>\` or \`<t:${seconds2}>\`\n- **<t:${seconds2}:F>:** \`<t:${seconds2}:F>\`\n- **<t:${seconds2}:R>:** \`<t:${seconds2}:R>\``;
29+
break;
30+
default:
31+
response = `❌ Unknown command! Please use \`-t ${tag}\` to see all available commands.`;
32+
};
33+
34+
return response;
35+
};

0 commit comments

Comments
 (0)