generated from EliasSchaut/DiscordBotTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Lila-Kuhlt/dev
Dev
- Loading branch information
Showing
29 changed files
with
1,130 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// See also: https://github.com/EliasSchaut/Discord-Bot-Template/wiki/How-to-command | ||
|
||
const { get_text: gt } = require("../../lang/lang_man") | ||
const s = "commands.bday." | ||
const { MessageEmbed } = require("discord.js") | ||
const dayjs = require("dayjs") | ||
const isSameOrBefore = require('dayjs/plugin/isSameOrBefore') | ||
dayjs.extend(isSameOrBefore) | ||
const objectSupport = require("dayjs/plugin/objectSupport") | ||
dayjs.extend(objectSupport) | ||
const relativeTime = require('dayjs/plugin/relativeTime') | ||
dayjs.extend(relativeTime) | ||
const horoscope = require("horoscope") | ||
|
||
module.exports = { | ||
name: 'bday', | ||
description: async function (msg) { return await gt(msg, s + "help") }, | ||
aliases: ['bd'], | ||
args_needed: false, | ||
args_min_length: 0, | ||
args_max_length: 1, | ||
usage: async function (msg) { return await gt(msg, s + "usage") }, | ||
guild_only: true, | ||
disabled: false, | ||
enable_slash: true, | ||
async execute(msg, args) { | ||
// ---------------------------- | ||
// Checker | ||
// ---------------------------- | ||
let member_id | ||
if (args.length === 0) { | ||
member_id = msg.author.id | ||
|
||
} else if (/^<@!?\d+>$/.test(args[0])) { | ||
member_id = args[0].match(/\d+/)[0] | ||
|
||
} else if (/\d+/.test(args[0])) { | ||
member_id = args[0] | ||
|
||
} else { | ||
return await msg.client.output.reply(msg, await gt(msg, `${s}fail.wrong_format`)) | ||
} | ||
|
||
try { | ||
await msg.guild.members.fetch(member_id) | ||
} catch (e) { | ||
return await msg.client.output.reply(msg, await gt(msg, `${s}fail.unknown_user`)) | ||
} | ||
const bday_tag = await msg.client.DB.Bday.get(msg.client, msg.guildId, member_id) | ||
if (bday_tag === null) return await msg.client.output.reply(msg, await gt(msg, `${s}fail.user_opt_out`)) | ||
// ---------------------------- | ||
|
||
// success | ||
const embed = await this.post_embed_success(msg, member_id, bday_tag.year, bday_tag.month, bday_tag.day) | ||
await msg.client.output.send(msg, { embeds: [embed] }) | ||
}, | ||
async post_embed_success(msg, bday_member_id, year, month, day) { | ||
return new MessageEmbed() | ||
.setColor(msg.client.config.embed.color) | ||
.setAuthor({ name: msg.client.config.embed.author_name, iconURL: msg.client.config.embed.avatar_url }) | ||
.setTitle(await gt(msg, `${s}embed.title`)) | ||
.addFields( | ||
await this.generate_general_field(msg, bday_member_id, year, month, day), | ||
await this.generate_star_sign_field(msg, month, day), | ||
await this.generate_time_calcs_field(msg, bday_member_id, year, month, day), | ||
) | ||
}, | ||
async generate_general_field(msg, bday_member_id, year, month, day) { | ||
const date = dayjs(new Date(year, month, day)) | ||
const age = dayjs().year() - year - dayjs().isSameOrBefore({ month :month, day :day }) | ||
const format = msg.client.config.date.format | ||
return { | ||
name: await gt(msg, `${s}embed.fields.general`), | ||
value: await gt(msg, `${s}success`, bday_member_id, date.format(format), age) | ||
} | ||
}, | ||
async generate_star_sign_field(msg, month, day) { | ||
const sign = horoscope.getSign({ month: (month + 1), day: day }) | ||
const output_sign = await gt(msg, `${s}zodiac.signs.${sign}`) | ||
const description = await gt(msg, `${s}zodiac.sign_descriptions.${sign}`) | ||
return { | ||
name: await gt(msg, `${s}embed.fields.zodiac`, output_sign), | ||
value: description | ||
} | ||
}, | ||
async generate_time_calcs_field(msg, bday_member_id, year, month, day) { | ||
const date = dayjs({ year: year, month: month, day: day }) | ||
const now = dayjs() | ||
const diff = dayjs.duration(now.diff(date)) | ||
const days = await gt(msg, `${s}embed.fields.time_calcs.days`, parseInt(diff.asDays())) | ||
const h = await gt(msg, `${s}embed.fields.time_calcs.h`, parseInt(diff.asHours())) | ||
const ms = await gt(msg, `${s}embed.fields.time_calcs.ms`, diff.asMilliseconds()) | ||
const join = await gt(msg, `${s}embed.fields.time_calcs.or`) | ||
|
||
return { | ||
name: await gt(msg, `${s}embed.fields.time_calcs.title`), | ||
value: await gt(msg, `${s}embed.fields.time_calcs.value`, bday_member_id, [days, h, ms].join(join)) | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// See also: https://github.com/EliasSchaut/Discord-Bot-Template/wiki/How-to-command | ||
|
||
const { get_text: gt } = require("../../lang/lang_man") | ||
const dayjs = require("dayjs") | ||
const customParseFormat = require('dayjs/plugin/customParseFormat') | ||
dayjs.extend(customParseFormat) | ||
const s = "commands.bday_all." | ||
const { MessageEmbed } = require("discord.js") | ||
|
||
module.exports = { | ||
name: 'bday_all', | ||
description: async function (msg) { return await gt(msg, s + "help") }, | ||
aliases: ['bdaya', 'bda'], | ||
args_needed: false, | ||
args_min_length: 0, | ||
args_max_length: 0, | ||
guild_only: true, | ||
disabled: false, | ||
enable_slash: true, | ||
async execute(msg, args) { | ||
const user_ids = await msg.client.DB.Bday.get_user_ids(msg.client, msg.guildId) | ||
const months = new Array(12).fill(0).map(() => { return [] }) | ||
|
||
for (const user_id of user_ids) { | ||
try { | ||
await msg.guild.members.fetch(user_id) | ||
} catch (e) { | ||
continue | ||
} | ||
const tag = await msg.client.DB.Bday.get(msg.client, msg.guildId, user_id) | ||
if (tag === null) continue | ||
|
||
const bdate = dayjs(new Date(tag.year, tag.month, tag.day)).format(msg.client.config.date.format) | ||
months[tag.month].push(await gt(msg, `${s}embed.bday_entry`, bdate, user_id)) | ||
} | ||
|
||
const embed = new MessageEmbed() | ||
.setAuthor({ name: msg.client.config.embed.author_name, iconURL: msg.client.config.embed.avatar_url }) | ||
.setColor(msg.client.config.embed.color) | ||
.setTitle(await gt(msg, `${s}embed.title`)) | ||
|
||
|
||
for (let i = 0; i < months.length; i++) { | ||
if (months[i].length === 0) continue | ||
|
||
const month_name = await gt(msg, `${s}months.${i}`) | ||
months[i].sort() | ||
embed.addField(month_name, months[i].join("\n"), true) | ||
} | ||
|
||
msg.client.output.send(msg, { embeds: [embed] }) | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// See also: https://github.com/EliasSchaut/Discord-Bot-Template/wiki/How-to-command | ||
|
||
const { get_text: gt } = require("../../lang/lang_man") | ||
const s = "commands.bday_disable." | ||
|
||
module.exports = { | ||
name: 'bday_disable', | ||
description: async function (msg) { return await gt(msg, s + "help") }, | ||
aliases: ['bdayd', 'bdd'], | ||
args_needed: false, | ||
args_min_length: 0, | ||
args_max_length: 0, | ||
guild_only: true, | ||
need_permission: ['ADMINISTRATOR'], | ||
disabled: false, | ||
enable_slash: false, | ||
async execute(msg, args) { | ||
await msg.client.DB.Guild.set_bday_disable(msg.client, msg.member.guild.id) | ||
await msg.client.output.send(msg, await gt(msg, s + "success")) | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// See also: https://github.com/EliasSchaut/Discord-Bot-Template/wiki/How-to-command | ||
|
||
const { get_text: gt } = require("../../lang/lang_man") | ||
const s = "commands.bday_enable." | ||
|
||
module.exports = { | ||
name: 'bday_enable', | ||
description: async function (msg) { return await gt(msg, s + "help") }, | ||
aliases: ['bdaye', 'bde'], | ||
args_needed: false, | ||
args_min_length: 0, | ||
args_max_length: 0, | ||
guild_only: true, | ||
need_permission: ['ADMINISTRATOR'], | ||
disabled: false, | ||
enable_slash: false, | ||
async execute(msg, args) { | ||
if (!await msg.client.DB.Guild.get_bday_channel_id(msg.client, msg.member.guild.id)) { | ||
await msg.client.output.reply(msg, await gt(msg, s + "fail.channel_not_set")) | ||
return | ||
} | ||
|
||
await msg.client.DB.Guild.set_bday_enable(msg.client, msg.member.guild.id) | ||
await msg.client.output.send(msg, await gt(msg, s + "success")) | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// See also: https://github.com/EliasSchaut/Discord-Bot-Template/wiki/How-to-command | ||
|
||
const { get_text: gt } = require("../../lang/lang_man") | ||
const dayjs = require("dayjs") | ||
const duration = require('dayjs/plugin/duration') | ||
dayjs.extend(duration) | ||
const isSameOrBefore = require('dayjs/plugin/isSameOrBefore') | ||
dayjs.extend(isSameOrBefore) | ||
const objectSupport = require("dayjs/plugin/objectSupport") | ||
dayjs.extend(objectSupport) | ||
const { MessageEmbed } = require("discord.js") | ||
const s = "commands.bday_next." | ||
|
||
module.exports = { | ||
name: 'bday_next', | ||
description: async function (msg) { return await gt(msg, s + "help") }, | ||
aliases: ['bdayn', 'bdn'], | ||
args_needed: false, | ||
args_min_length: 0, | ||
args_max_length: 0, | ||
guild_only: true, | ||
disabled: false, | ||
enable_slash: true, | ||
async execute(msg, args) { | ||
const user_ids = await msg.client.DB.Bday.get_user_ids(msg.client, msg.guildId) | ||
const min = { day_distance: 400, user_ids: [-1] } // M = 400 | ||
const now = dayjs() | ||
|
||
for (const user_id of user_ids) { | ||
try { | ||
await msg.guild.members.fetch(user_id) | ||
} catch (e) { | ||
continue | ||
} | ||
const tag = await msg.client.DB.Bday.get(msg.client, msg.guildId, user_id) | ||
if (tag === null) continue | ||
|
||
const bdate = dayjs({ day: tag.day, month: tag.month }) | ||
const day_distance = dayjs.duration(bdate.diff(dayjs(now))).asDays() | ||
if (day_distance < 0) continue | ||
|
||
const day_distance_int = parseInt(day_distance) | ||
if (day_distance_int < min.day_distance) { | ||
min.day_distance = day_distance_int | ||
min.user_ids = [user_id] | ||
|
||
} else if (day_distance_int === min.day_distance) { | ||
min.user_ids.push(user_id) | ||
} | ||
} | ||
|
||
if (min.user_ids === [-1]) return await msg.client.output.send(msg, await gt(msg, `${s}fail.nothing_found`)) | ||
for (const user_id of min.user_ids) { | ||
const format = msg.client.config.date.format | ||
const tag = await msg.client.DB.Bday.get(msg.client, msg.guildId, user_id) | ||
const bdate = dayjs({ day: tag.day, month: tag.month, year: tag.year }) | ||
const new_age = dayjs().year() - tag.year - dayjs().isSameOrBefore({ month: tag.month, day: tag.day }) + 1 | ||
|
||
const embed = new MessageEmbed() | ||
.setColor(msg.client.config.embed.color) | ||
|
||
if (min.day_distance === 0) { | ||
embed.setDescription(await gt(msg, `${s}embed.description_sg`, user_id, new_age, bdate.format(format))) | ||
} else { | ||
embed.setDescription(await gt(msg, `${s}embed.description_pl`, user_id, min.day_distance + 1, new_age, bdate.format(format))) | ||
} | ||
await msg.client.output.send(msg, { embeds: [embed] }) | ||
} | ||
}, | ||
}; |
Oops, something went wrong.