Compare commits
2 commits
b83a1d3053
...
21e69cf0c2
Author | SHA1 | Date | |
---|---|---|---|
21e69cf0c2 | |||
0bdd2af66e |
2 changed files with 41 additions and 7 deletions
|
@ -27,9 +27,9 @@ export default async () => {
|
||||||
console.log('Translations progression :');
|
console.log('Translations progression :');
|
||||||
client.locales = await loadLocales(client.config.default_lang);
|
client.locales = await loadLocales(client.config.default_lang);
|
||||||
|
|
||||||
client.db = new Database(`${
|
client.db = new Database(`${process.env.DOCKERIZED === '1' ? '/config' : './config'}/db.sqlite3`);
|
||||||
process.env.DOCKERIZED === '1' ? '/config' : './config'
|
|
||||||
}/db.sqlite3`);
|
initDatabase(client.db);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
};
|
};
|
||||||
|
@ -41,3 +41,19 @@ export const quit = (client: Client) => {
|
||||||
// Close client
|
// Close client
|
||||||
client.destroy();
|
client.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const initDatabase = (db: Database) => {
|
||||||
|
// Table for reminders
|
||||||
|
db.run('CREATE TABLE IF NOT EXISTS reminder ( \
|
||||||
|
id INTEGER PRIMARY KEY, \
|
||||||
|
data TEXT, \
|
||||||
|
expiration_date INTEGER, \
|
||||||
|
message_id INTEGER, \
|
||||||
|
option_id INTEGER, \
|
||||||
|
channel_id INTEGER, \
|
||||||
|
creation_date INTEGER, \
|
||||||
|
user_id INTEGER, \
|
||||||
|
guild_id INTEGER \
|
||||||
|
);');
|
||||||
|
};
|
||||||
|
|
|
@ -10,16 +10,34 @@ export const showDate = (
|
||||||
locale: Map<string, unknown>,
|
locale: Map<string, unknown>,
|
||||||
date: Date
|
date: Date
|
||||||
) => {
|
) => {
|
||||||
return date.toLocaleString(tz).replace(' ', ` ${
|
return date.toLocaleString(tz).replace(' ', ` ${locale.get('u_time_at')} `);
|
||||||
locale.get('u_time_at')
|
|
||||||
} `);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TimeSecond {
|
||||||
|
Year = 31536000,
|
||||||
|
Week = 604800,
|
||||||
|
Day = 86400,
|
||||||
|
Hour = 3600,
|
||||||
|
Minute = 60,
|
||||||
|
Second = 1
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take a cooldown, for example 2min and transform it to seconds, here: 120s
|
* Take a cooldown, for example 2min and transform it to seconds, here: 120s
|
||||||
* @param time time in human format
|
* @param time time in human format
|
||||||
* @returns time in seconds
|
* @returns time in seconds
|
||||||
*/
|
*/
|
||||||
export const strToSeconds = (time: string) => {
|
export const strToSeconds = (time: string) => {
|
||||||
return 0;
|
const regex = new RegExp(`(?<${TimeSecond[TimeSecond.Year]}>[0-9]+(?=[y|a]))|(?<${TimeSecond[TimeSecond.Week]}>[0-9]+(?=[w]))|(?<${TimeSecond[TimeSecond.Day]}>[0-9]+(?=[d|j]))|(?<${TimeSecond[TimeSecond.Hour]}>[0-9]+(?=[h]))|(?<${TimeSecond[TimeSecond.Minute]}>[0-9]+(?=[m]))|(?<${TimeSecond[TimeSecond.Second]}>[0-9]+(?=[s]?))`);
|
||||||
|
|
||||||
|
const data = Object.assign({}, regex.exec(time)?.groups);
|
||||||
|
|
||||||
|
let res = 0;
|
||||||
|
Object.entries(data).forEach(([key, value]) => {
|
||||||
|
if (value) {
|
||||||
|
res += +value * TimeSecond[key as keyof typeof TimeSecond];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue