-
Notifications
You must be signed in to change notification settings - Fork 4
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 #76 from oof2win2/master
New linking support
- Loading branch information
Showing
11 changed files
with
375 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const Discord = require("discord.js"); | ||
const { searchOneDB, giveFactorioRole, insertOneDB, findOneAndReplaceDB } = require("../../functions"); | ||
const { LinkingCache } = require("../../functions"); | ||
const { ErrorManager } = require("../../utils/error-manager"); | ||
const lodash = require("lodash"); | ||
let { linkConfirmation } = require("../../config/messages.json") | ||
|
||
module.exports = { | ||
config: { | ||
name: "linkme", | ||
aliases: [], | ||
usage: "<linking ID>", | ||
category: "factorio", | ||
description: "Link yourself to Factorio", | ||
accessableby: "Members", | ||
}, | ||
run: async (client, message, args) => { | ||
if (!args[0]) { | ||
return message.channel.send("Provide a linking ID!"); | ||
} | ||
let linkingID | ||
try { | ||
linkingID = parseInt(args[0]); | ||
if (Number.isNaN(linkingID)) return message.channel.send("Provide a number given by the server, not a string!"); | ||
} catch (error) { | ||
ErrorManager.Error(error); | ||
return message.channel.send(`Error: ${error}`); | ||
} | ||
const factorioName = LinkingCache.take(linkingID); | ||
if (factorioName === undefined) | ||
return message.channel.send("Wrong linking ID or timed out!"); | ||
|
||
linkConfirmation = linkConfirmation.replace("%%USERNAME%%", message.author.username); | ||
linkConfirmation = linkConfirmation.replace("%%FACTORIONAME%%", factorioName) | ||
let confirmationMsg = await message.channel.send(linkConfirmation); | ||
confirmationMsg.react("✅"); | ||
confirmationMsg.react("🔨"); | ||
confirmationMsg.react("❌"); | ||
|
||
const filter = (reaction, user) => { | ||
return user.id == message.author.id; | ||
} | ||
|
||
let reactions; | ||
try { | ||
reactions = await confirmationMsg.awaitReactions(filter, { max: 1, time: 60 * 1000, errors: ["time"]}); | ||
} catch (error) { | ||
if (error.size === 0) return message.channel.send("Timed out!") | ||
else ErrorManager.Error(error); | ||
return message.channel.send("Error getting reaction"); | ||
} | ||
const reaction = reactions.first(); | ||
const dat = { factorioName: factorioName, discordID: message.author.id }; | ||
const found = await searchOneDB("otherData", "linkedPlayers", { | ||
discordID: message.author.id, | ||
}); | ||
|
||
if (reaction.emoji.name == "❌") | ||
return message.channel.send("Linking cancelled!"); | ||
if (found !== null && reaction.emoji.name === "🔨") { | ||
// re-link user | ||
let res = await findOneAndReplaceDB( | ||
"otherData", | ||
"linkedPlayers", | ||
found, | ||
dat | ||
); | ||
if (res.ok != 1) | ||
return message.channel.send( | ||
"Please contact devs/admins for re-linking, process failed" | ||
); | ||
//redo statistics | ||
let prevStats = await searchOneDB("otherData", "globPlayerStats", { | ||
discordID: found.discordID, | ||
}); | ||
let newStats = lodash.cloneDeep(prevStats); | ||
newStats.factorioName = factorioName; | ||
res = await findOneAndReplaceDB( | ||
"otherData", | ||
"globPlayerStats", | ||
prevStats, | ||
newStats | ||
); | ||
if (res.ok != 1) | ||
return message.channel.send( | ||
"Please contact devs/admins for re-linking, process failed" | ||
); | ||
message.channel.send("Re-linked succesfully!"); | ||
giveFactorioRole(factorioName, "Member"); // give the Member role to new players | ||
} | ||
if (found !== null && reaction.emoji.name == "✅") return message.channel.send("Already linked!"); | ||
if (found === null && reaction.emoji.name == "✅") { | ||
const toInsert = { | ||
factorioName: `${factorioName}`, | ||
discordID: `${message.author.id}`, | ||
} | ||
try { | ||
giveFactorioRole(factorioName, "Member"); // give the Member role to new players | ||
let res = await insertOneDB("otherData", "linkedPlayers", toInsert); | ||
if (res.result.ok == true) return message.channel.send("Linked successfully!"); | ||
else return message.channel.send("Didn't insert correctly into database"); | ||
} catch (error) { | ||
ErrorManager.Error(error); | ||
return message.channel.send("Error inserting into database"); | ||
} | ||
} | ||
}, | ||
}; |
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,58 @@ | ||
const Discord = require("discord.js"); | ||
const { searchOneDB, getFactorioRoles } = require("../../functions"); | ||
const { LinkingCache } = require("../../functions"); | ||
const { ErrorManager } = require("../../utils/error-manager"); | ||
const lodash = require("lodash"); | ||
let { linkConfirmation } = require("../../config/messages.json") | ||
|
||
module.exports = { | ||
config: { | ||
name: "getfactorioroles", | ||
aliases: [], | ||
usage: "<mention/Factorio name>", | ||
category: "moderator", | ||
description: "Gives a user a Factorio role", | ||
accessableby: "Moderator", | ||
}, | ||
run: async (client, message, args) => { | ||
let authRoles = message.member.roles.cache; | ||
if ( | ||
!authRoles.some((r) => ["Admin", "Moderator", "dev"].includes(r.name)) | ||
) { | ||
// if user is not Admin/Moderator/dev | ||
return message.channel.send( | ||
"You don't have enough priviliges to run this command!" | ||
); | ||
} | ||
if (!args[0] && !message.mentions.users.first()) | ||
return message.channel.send("Give a Factorio name/Discord ping!") | ||
let user; | ||
if (message.mentions.users.first()) { | ||
let res = await searchOneDB("otherData", "linkedPlayers", { | ||
discordID: (message.mentions.users.first()).id, | ||
}) | ||
if (res == undefined) | ||
return message.channel.send("User not linked!"); | ||
user = res.factorioName; | ||
} else { | ||
user = args[0]; | ||
} | ||
|
||
let rolesEmbed = new Discord.MessageEmbed() | ||
.setTitle("Roles of a Factorio player") | ||
.setDescription("Roles of a Factorio player") | ||
.setColor("GREEN") | ||
.setAuthor( | ||
`${message.guild.me.displayName} Help`, | ||
message.guild.iconURL | ||
) | ||
.setThumbnail(client.user.displayAvatarURL()) | ||
.setFooter( | ||
`© ${message.guild.me.displayName} | Developed by DistroByte & oof2win2 | Total Commands: ${client.commands.size}`, | ||
client.user.displayAvatarURL() | ||
); | ||
const roles = (await getFactorioRoles(user)).roles; | ||
rolesEmbed.addField("\u200B", roles.join(", ")); | ||
return message.channel.send(rolesEmbed); | ||
}, | ||
}; |
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,50 @@ | ||
const Discord = require("discord.js"); | ||
const { searchOneDB, giveFactorioRole, insertOneDB, findOneAndReplaceDB } = require("../../functions"); | ||
const { LinkingCache } = require("../../functions"); | ||
const { ErrorManager } = require("../../utils/error-manager"); | ||
const lodash = require("lodash"); | ||
let { linkConfirmation } = require("../../config/messages.json") | ||
|
||
module.exports = { | ||
config: { | ||
name: "givefactoriorole", | ||
aliases: [], | ||
usage: "<mention/Factorio name> <role name>", | ||
category: "moderator", | ||
description: "Gives a user a Factorio role", | ||
accessableby: "Moderator", | ||
}, | ||
run: async (client, message, args) => { | ||
let authRoles = message.member.roles.cache; | ||
if ( | ||
!authRoles.some((r) => ["Admin", "Moderator", "dev"].includes(r.name)) | ||
) { | ||
// if user is not Admin/Moderator/dev | ||
return message.channel.send( | ||
"You don't have enough priviliges to run this command!" | ||
); | ||
} | ||
if (!args[0] && !message.mentions.users.first()) | ||
return message.channel.send("Give a Factorio name/Discord ping!") | ||
if (!args[1]) | ||
return message.channel.send("Give role to assign!") | ||
|
||
let user; | ||
if (message.mentions.users.first()) { | ||
let res = await searchOneDB("otherData", "linkedPlayers", { | ||
discordID: (message.mentions.users.first()).id, | ||
}) | ||
if (res == undefined) | ||
return message.channel.send("User not linked!"); | ||
user = res.factorioName; | ||
} else { | ||
user = args[0]; | ||
} | ||
const role = args[1]; | ||
let res = await giveFactorioRole(user, role); | ||
if (res == false) return message.channel.send("User already has role!"); | ||
if (res.ok == true) | ||
return message.channel.send("Assigned role successfully!"); | ||
return message.channel.send("Error adding to database"); | ||
}, | ||
}; |
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,47 @@ | ||
const Discord = require("discord.js"); | ||
const { searchOneDB, removeFactorioRole } = require("../../functions"); | ||
const { ErrorManager } = require("../../utils/error-manager"); | ||
|
||
module.exports = { | ||
config: { | ||
name: "removefactoriorole", | ||
aliases: [], | ||
usage: "<mention/Factorio name> <role name>", | ||
category: "moderator", | ||
description: "Removes Factorio role from a user", | ||
accessableby: "Moderator", | ||
}, | ||
run: async (client, message, args) => { | ||
let authRoles = message.member.roles.cache; | ||
if ( | ||
!authRoles.some((r) => ["Admin", "Moderator", "dev"].includes(r.name)) | ||
) { | ||
// if user is not Admin/Moderator/dev | ||
return message.channel.send( | ||
"You don't have enough priviliges to run this command!" | ||
); | ||
} | ||
if (!args[0] && !message.mentions.users.first()) | ||
return message.channel.send("Give a Factorio name/Discord ping!") | ||
if (!args[1]) | ||
return message.channel.send("Give role to remove!") | ||
|
||
let username; | ||
if (message.mentions.users.first()) { | ||
let res = await searchOneDB("otherData", "linkedPlayers", { | ||
discordID: (message.mentions.users.first()).id, | ||
}) | ||
if (res == undefined) | ||
return message.channel.send("User not linked!"); | ||
username = res.factorioName; | ||
} else { | ||
username = args[0]; | ||
} | ||
const role = args[1]; | ||
let res = await removeFactorioRole(username, role); | ||
if (res == false) return message.channel.send("User doesn't have roles!") | ||
if (res.ok == true) | ||
return message.channel.send("Removed role successfully!"); | ||
return message.channel.send("Error adding to database"); | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"firstJoinMessage": "Heyas! Welcome to the AwF community. Since you are new, you don't have many permissions. For those, please go to the http://awf.yt Discord" | ||
} | ||
"firstJoinMessage": "Heyas! Welcome to the AwF community. Since you are new, you don't have many permissions. For those, please go to the http://awf.yt Discord", | ||
"linkConfirmation": "You have chosen to link your Discord account, %%USERNAME%% with your Factorio account on AwF, %%FACTORIONAME%%. The request will timeout after 1 minute of sending. React with :hammer: to re-link your account. If complications arise, please contact devs/admins (relinking is when switching Factorio username, for switching Discord account contact admins/devs. Changing your Discord username **IS NOT** changing an account, whilst changing your Factorio username **is**)" | ||
} |
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
Oops, something went wrong.