Skip to content

Commit

Permalink
Merge pull request #7 from saiteja-madha/feat-flagtr
Browse files Browse the repository at this point in the history
Feat flag-tr
  • Loading branch information
saiteja-madha authored Aug 28, 2021
2 parents e9792e4 + 3e4aef1 commit deee244
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 110 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ascii-table": "0.0.9",
"axios": "^0.21.1",
"btoa": "^1.2.1",
"country-language": "^0.1.7",
"discord.js": "^13.1.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
Expand Down
78 changes: 78 additions & 0 deletions src/commands/admin/flag-translation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const { Command, CommandContext } = require("@src/structures");
const db = require("@schemas/guild-schema");

module.exports = class FlagTranslation extends Command {
constructor(client) {
super(client, {
name: "flagtr",
description: "setup flag translation",
minArgsCount: 1,
subcommands: [
{
trigger: "<ON|OFF>",
description: "enable or disable translation by flags",
},
{
trigger: "status",
description: "flag translation status",
},
{
trigger: "add <#channel(s)>",
description: "add channels where flag translation must occur",
},
{
trigger: "remove <#channel(s)>",
description: "remove channels with flag translations enabled",
},
],
category: "ADMIN",
userPermissions: ["ADMINISTRATOR"],
});
}

/**
* @param {CommandContext} ctx
*/
async run(ctx) {
const { args, message } = ctx;
const input = args[0].toLowerCase();
const mentions = message.mentions.channels.map((ch) => ch.id);
const settings = await db.getSettings(message.guild);

switch (input) {
case "add":
if (mentions.size === 0) return message.reply("Incorrect usage! You need to mentions channels");
let toAdd = [...new Set([...mentions, ...settings.flag_translation.channels])];
await db.setFlagTrChannels(message.guildId, toAdd);
ctx.reply("Success! Configuration saved");
break;

case "remove":
if (mentions.size === 0) return message.reply("Incorrect usage! You need to mentions channels");
let newIds = settings.flag_translation.channels.filter((item) => !mentions.includes(item));
await db.setFlagTrChannels(message.guildId, newIds);
ctx.reply("Success! Configuration saved");
break;

case "status":
if (!settings.flag_translation.enabled) return await ctx.reply("Flag translation is disabled in this server");
let channels = settings.flag_translation.channels
.filter((id) => message.guild.channels.cache.has(id))
.map((id) => message.guild.channels.cache.get(id).toString())
.join(", ");

if (!channels) return ctx.reply("Flag translation is enabled in all channels");
ctx.reply("Flag translation is enabled in following channels: \n" + channels);
break;

default:
let status;
if (input === "none" || input === "off" || input === "disable") status = false;
else if (input === "on" || input === "enable") status = true;
else return message.reply("Incorrect Command Usage");

await db.flagTranslation(message.guildId, status);
ctx.reply(`Configuration saved! Flag translation is now ${status ? "enabled" : "disabled"}`);
}
}
};
3 changes: 3 additions & 0 deletions src/commands/admin/greeting/farewell.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ module.exports = class Farewell extends Command {
.catch((_) => ctx.reply("Failed to save configuration"));
break;

case "preview":
return await sendPreview(ctx);

case "desc":
return await setDescription(ctx);

Expand Down
110 changes: 1 addition & 109 deletions src/commands/utility/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { MessageEmbed } = require("discord.js");
const { Command, CommandContext } = require("@src/structures");
const { EMBED_COLORS } = require("@root/config.js");
const { translate } = require("@utils/httpUtils");
const { GOOGLE_TRANSLATE } = require("@src/data.json");

module.exports = class TranslateCommand extends Command {
constructor(client) {
Expand Down Expand Up @@ -49,112 +50,3 @@ module.exports = class TranslateCommand extends Command {
ctx.reply({ embeds: [embed] });
}
};

const GOOGLE_TRANSLATE = {
auto: "Automatic",
af: "Afrikaans",
sq: "Albanian",
am: "Amharic",
ar: "Arabic",
hy: "Armenian",
az: "Azerbaijani",
eu: "Basque",
be: "Belarusian",
bn: "Bengali",
bs: "Bosnian",
bg: "Bulgarian",
ca: "Catalan",
ceb: "Cebuano",
ny: "Chichewa",
"zh-CN": "Chinese (Simplified)",
"zh-TW": "Chinese (Traditional)",
co: "Corsican",
hr: "Croatian",
cs: "Czech",
da: "Danish",
nl: "Dutch",
en: "English",
eo: "Esperanto",
et: "Estonian",
tl: "Filipino",
fi: "Finnish",
fr: "French",
fy: "Frisian",
gl: "Galician",
ka: "Georgian",
de: "German",
el: "Greek",
gu: "Gujarati",
ht: "Haitian Creole",
ha: "Hausa",
haw: "Hawaiian",
he: "Hebrew",
iw: "Hebrew",
hi: "Hindi",
hmn: "Hmong",
hu: "Hungarian",
is: "Icelandic",
ig: "Igbo",
id: "Indonesian",
ga: "Irish",
it: "Italian",
ja: "Japanese",
jw: "Javanese",
kn: "Kannada",
kk: "Kazakh",
km: "Khmer",
ko: "Korean",
ku: "Kurdish (Kurmanji)",
ky: "Kyrgyz",
lo: "Lao",
la: "Latin",
lv: "Latvian",
lt: "Lithuanian",
lb: "Luxembourgish",
mk: "Macedonian",
mg: "Malagasy",
ms: "Malay",
ml: "Malayalam",
mt: "Maltese",
mi: "Maori",
mr: "Marathi",
mn: "Mongolian",
my: "Myanmar (Burmese)",
ne: "Nepali",
no: "Norwegian",
ps: "Pashto",
fa: "Persian",
pl: "Polish",
pt: "Portuguese",
pa: "Punjabi",
ro: "Romanian",
ru: "Russian",
sm: "Samoan",
gd: "Scots Gaelic",
sr: "Serbian",
st: "Sesotho",
sn: "Shona",
sd: "Sindhi",
si: "Sinhala",
sk: "Slovak",
sl: "Slovenian",
so: "Somali",
es: "Spanish",
su: "Sundanese",
sw: "Swahili",
sv: "Swedish",
tg: "Tajik",
ta: "Tamil",
te: "Telugu",
th: "Thai",
tr: "Turkish",
uk: "Ukrainian",
ur: "Urdu",
uz: "Uzbek",
vi: "Vietnamese",
cy: "Welsh",
xh: "Xhosa",
yi: "Yiddish",
yo: "Yoruba",
zu: "Zulu",
};
138 changes: 138 additions & 0 deletions src/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"GOOGLE_TRANSLATE": {
"auto": "Automatic",
"af": "Afrikaans",
"sq": "Albanian",
"am": "Amharic",
"ar": "Arabic",
"hy": "Armenian",
"az": "Azerbaijani",
"eu": "Basque",
"be": "Belarusian",
"bn": "Bengali",
"bs": "Bosnian",
"bg": "Bulgarian",
"ca": "Catalan",
"ceb": "Cebuano",
"ny": "Chichewa",
"zh-CN": "Chinese (Simplified)",
"zh-TW": "Chinese (Traditional)",
"co": "Corsican",
"hr": "Croatian",
"cs": "Czech",
"da": "Danish",
"nl": "Dutch",
"en": "English",
"eo": "Esperanto",
"et": "Estonian",
"tl": "Filipino",
"fi": "Finnish",
"fr": "French",
"fy": "Frisian",
"gl": "Galician",
"ka": "Georgian",
"de": "German",
"el": "Greek",
"gu": "Gujarati",
"ht": "Haitian Creole",
"ha": "Hausa",
"haw": "Hawaiian",
"he": "Hebrew",
"iw": "Hebrew",
"hi": "Hindi",
"hmn": "Hmong",
"hu": "Hungarian",
"is": "Icelandic",
"ig": "Igbo",
"id": "Indonesian",
"ga": "Irish",
"it": "Italian",
"ja": "Japanese",
"jw": "Javanese",
"kn": "Kannada",
"kk": "Kazakh",
"km": "Khmer",
"ko": "Korean",
"ku": "Kurdish (Kurmanji)",
"ky": "Kyrgyz",
"lo": "Lao",
"la": "Latin",
"lv": "Latvian",
"lt": "Lithuanian",
"lb": "Luxembourgish",
"mk": "Macedonian",
"mg": "Malagasy",
"ms": "Malay",
"ml": "Malayalam",
"mt": "Maltese",
"mi": "Maori",
"mr": "Marathi",
"mn": "Mongolian",
"my": "Myanmar (Burmese)",
"ne": "Nepali",
"no": "Norwegian",
"ps": "Pashto",
"fa": "Persian",
"pl": "Polish",
"pt": "Portuguese",
"pa": "Punjabi",
"ro": "Romanian",
"ru": "Russian",
"sm": "Samoan",
"gd": "Scots Gaelic",
"sr": "Serbian",
"st": "Sesotho",
"sn": "Shona",
"sd": "Sindhi",
"si": "Sinhala",
"sk": "Slovak",
"sl": "Slovenian",
"so": "Somali",
"es": "Spanish",
"su": "Sundanese",
"sw": "Swahili",
"sv": "Swedish",
"tg": "Tajik",
"ta": "Tamil",
"te": "Telugu",
"th": "Thai",
"tr": "Turkish",
"uk": "Ukrainian",
"ur": "Urdu",
"uz": "Uzbek",
"vi": "Vietnamese",
"cy": "Welsh",
"xh": "Xhosa",
"yi": "Yiddish",
"yo": "Yoruba",
"zu": "Zulu"
},
"UNICODE_LETTER": {
"🇦": "a",
"🇧": "b",
"🇨": "c",
"🇩": "d",
"🇪": "e",
"🇫": "f",
"🇬": "g",
"🇭": "h",
"🇮": "i",
"🇯": "j",
"🇰": "k",
"🇱": "l",
"🇲": "m",
"🇳": "n",
"🇴": "o",
"🇵": "p",
"🇶": "q",
"🇷": "r",
"🇸": "s",
"🇹": "t",
"🇺": "u",
"🇻": "v",
"🇼": "w",
"🇽": "x",
"🇾": "y",
"🇿": "z"
}
}
2 changes: 1 addition & 1 deletion src/features/automod.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function run(client) {

const settings = (await getSettings(message.guild)).automod;
if (!settings.anti_ghostping || !settings.log_channel) return;
const key = `${message.guild.id}|${message.channel.id}|${message.id}`;
const key = `${guild.id}|${channelId}|${id}`;

// deleted message has mentions and was previously cached
if (MESSAGE_CACHE.has(key)) {
Expand Down
Loading

0 comments on commit deee244

Please sign in to comment.