Skip to content

Commit 51baf83

Browse files
authored
Merge pull request #137 from oof2win2/feat/djs-v13
2 parents 8ebfb0c + 0c1372a commit 51baf83

File tree

20 files changed

+7545
-251
lines changed

20 files changed

+7545
-251
lines changed

package-lock.json

Lines changed: 7328 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"colors-generator": "^0.3.4",
3232
"common-tags": "^1.8.0",
3333
"discord-giveaways": "^4.4.3",
34-
"discord.js": "^12.5.1",
34+
"discord.js": "^13.6.0",
3535
"ejs": "^3.1.6",
3636
"express": "^4.17.1",
3737
"express-session": "^1.17.1",
Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
import { Message, MessageAttachment } from "discord.js";
22
import { Command } from "../../base/Command.js";
33
import serverJS from "../../servers";
4-
import lastLines from "read-last-lines"
4+
import lastLines from "read-last-lines";
55

66
const Rollback: Command<Message> = {
7-
name: "getlogs",
8-
description: "Get logs from a Factorio server",
9-
usage: "(channel) [logcount]",
10-
category: "Administration",
11-
aliases: [],
12-
examples: ["{{p}}getlogs #awf-regular 50"],
13-
dirname: __dirname,
14-
enabled: true,
15-
guildOnly: false,
16-
memberPermissions: ["ADMINISTRATOR"],
17-
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
18-
nsfw: false,
19-
ownerOnly: false,
20-
customPermissions: ["MANAGE_SERVER"],
21-
run: async ({ client, message, args }) => {
22-
if (!message.mentions.channels.first())
23-
return message.reply("No channel to get logs of provided!");
24-
args.shift(); // remove mention
25-
const lineCount = Math.min(Number(args.shift()) || 50, 200)
26-
const server = serverJS.find(
27-
(server) => server.discordid === message.mentions.channels.first().id
28-
);
29-
if (!server) return message.reply("Invalid channel, not tied to a server!");
30-
const fullPath = `${client.config.serverpath}/${server.path}/factorio-current.log`
31-
const lines = await lastLines.read(fullPath, lineCount < 0 ? lineCount : 50)
32-
const attachment = new MessageAttachment(Buffer.from(lines), "log.txt")
33-
return message.channel.send(`Logs for <#${server.discordid}> are sent as an attachement`, {files: [attachment]})
34-
},
7+
name: "getlogs",
8+
description: "Get logs from a Factorio server",
9+
usage: "(channel) [logcount]",
10+
category: "Administration",
11+
aliases: [],
12+
examples: ["{{p}}getlogs #awf-regular 50"],
13+
dirname: __dirname,
14+
enabled: true,
15+
guildOnly: false,
16+
memberPermissions: ["ADMINISTRATOR"],
17+
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
18+
nsfw: false,
19+
ownerOnly: false,
20+
customPermissions: ["MANAGE_SERVER"],
21+
run: async ({ client, message, args }) => {
22+
if (!message.mentions.channels.first())
23+
return message.reply("No channel to get logs of provided!");
24+
args.shift(); // remove mention
25+
const lineCount = Math.min(Number(args.shift()) || 50, 200);
26+
const server = serverJS.find(
27+
(server) => server.discordid === message.mentions.channels.first().id
28+
);
29+
if (!server) return message.reply("Invalid channel, not tied to a server!");
30+
const fullPath = `${client.config.serverpath}/${server.path}/factorio-current.log`;
31+
const lines = await lastLines.read(
32+
fullPath,
33+
lineCount < 0 ? lineCount : 50
34+
);
35+
const attachment = new MessageAttachment(Buffer.from(lines), "log.txt");
36+
return message.channel.send({
37+
files: [attachment],
38+
content: `Logs for <#${server.discordid}> are sent as an attachement`,
39+
});
40+
},
3541
};
3642

3743
export default Rollback;

src/commands/Administration/resetserver.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ const Resetserver: Command<Message> = {
6969
}
7070
command = `${command} ${cmdArgs._}`.trim();
7171

72-
const reactionFilter = (reaction, user) => user.id === message.author.id;
7372
const confirm = await message.channel.send(
7473
`Are you sure you want to reset your server with this command?\n\`bin/x64/factorio ${command}\``
7574
);
7675
confirm.react("✅");
7776
confirm.react("❌");
7877
let reactions;
7978
try {
80-
reactions = await confirm.awaitReactions(reactionFilter, {
79+
reactions = await confirm.awaitReactions({
8180
max: 1,
8281
time: 120000,
82+
filter: (reaction, user) => user.id === message.author.id,
8383
});
8484
} catch {
8585
return message.channel.send("Error getting reaction");
@@ -150,10 +150,10 @@ const Resetserver: Command<Message> = {
150150
factorio.on("close", (code) => {
151151
let msg = output.join("\n");
152152
let file = new MessageAttachment(Buffer.from(msg), "output.txt");
153-
message.channel.send(
154-
`Process exited with code ${code}. Starting server back up. Roles will sync shortly`,
155-
{ files: [file] }
156-
);
153+
message.channel.send({
154+
files: [file],
155+
content: `Process exited with code ${code}. Starting server back up. Roles will sync shortly`,
156+
});
157157
childprocess.spawn(`./factorio-init/factorio`, ["start"], {
158158
detached: true,
159159
cwd: `${client.config.serverpath}/${server.path}`,

src/commands/Administration/startserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const Startserver: Command<Message> = {
4343
if (fs.statSync(dir.dir).isDirectory())
4444
choiceEmbed.addField(`\`${dir}\``, "\u200B"); //check if it is a directory and if yes add it to the embed
4545
});
46-
return message.channel.send(choiceEmbed);
46+
return message.channel.send({ embeds: [choiceEmbed] });
4747
} else {
4848
let serverFolder = serverJS.find(
4949
(server) => server.discordid === message.mentions.channels.first().id

src/commands/Administration/stopserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const Stopserver: Command<Message> = {
4646
if (fs.statSync(dir.dir).isDirectory())
4747
choiceEmbed.addField(`\`${dir}\``, "\u200B"); //check if it is a directory and if yes add it to the embed
4848
});
49-
return message.channel.send(choiceEmbed);
49+
return message.channel.send({ embeds: [choiceEmbed] });
5050
} else {
5151
let serverFolder;
5252
if (message.mentions.channels.first())

src/commands/Factorio/linkme.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,29 @@ const Linkme: Command<Message> = {
2828
);
2929
client.cache.linkingCache.del(`${args[0]}`);
3030
let embed = new MessageEmbed()
31-
.setAuthor(message.guild.name, message.guild.iconURL())
31+
.setAuthor({
32+
name: message.guild.name,
33+
iconURL: message.guild.iconURL(),
34+
})
3235
.setColor(client.config.embed.color)
3336
.setFooter(client.config.embed.footer);
34-
embed.addFields(
37+
embed.addFields([
3538
{ name: "Factorio name", value: linkID },
36-
{ name: "Discord user", value: message.author }
37-
);
39+
{ name: "Discord user", value: `<@${message.author.id}>` },
40+
]);
3841
embed.setDescription(
3942
"You have chosen to link youself. React with ✅ to confirm, ❌ to cancel. Will time out in 90s"
4043
);
4144

42-
const confirm = await message.channel.send(embed);
45+
const confirm = await message.channel.send({ embeds: [embed] });
4346
confirm.react("✅");
4447
confirm.react("❌");
45-
const reactionFilter = (reaction, user) => user.id == message.author.id;
4648
let reactions;
4749
try {
48-
reactions = await confirm.awaitReactions(reactionFilter, {
50+
reactions = await confirm.awaitReactions({
4951
max: 1,
5052
time: 120000,
51-
errors: ["time"],
53+
filter: (reaction, user) => user.id == message.author.id,
5254
});
5355
} catch {
5456
return message.channel.send("Timed out.");

src/commands/Factorio/onlineplayers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ const OnlinePlayers: Command<Message> = {
7575
players.join("\n") || "Nobody is online"
7676
);
7777
});
78-
return message.channel.send(embed);
78+
return message.channel.send({
79+
embeds: [embed],
80+
});
7981
},
8082
};
8183

src/commands/Factorio/statsg.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,26 @@ const StatsG: Command<Message> = {
3030
.setFooter(client.config.embed.footer);
3131
embed.setTitle("Global Factorio User Statistics");
3232
embed.setDescription(`Statistics of <@${userID}> | ${userID}`);
33-
embed.addFields(
34-
{ name: "Total Points", value: Math.round(user.factorioStats.points) },
35-
{ name: "Deaths", value: user.factorioStats.deaths },
36-
{ name: "Built Entities", value: user.factorioStats.builtEntities },
33+
embed.addFields([
34+
{
35+
name: "Total Points",
36+
value: Math.round(user.factorioStats.points).toString(),
37+
},
38+
{ name: "Deaths", value: user.factorioStats.deaths.toString() },
39+
{
40+
name: "Built Entities",
41+
value: user.factorioStats.builtEntities.toString(),
42+
},
3743
{
3844
name: "Time played (minutes)",
39-
value: Math.round((user.factorioStats.timePlayed / 54000) * 15),
40-
}
41-
);
42-
return message.channel.send(embed);
45+
value: Math.round(
46+
(user.factorioStats.timePlayed / 54000) * 15
47+
).toString(),
48+
},
49+
]);
50+
return message.channel.send({
51+
embeds: [embed],
52+
});
4353
},
4454
};
4555

src/commands/Factorio/statss.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ const StatsS: Command<Message> = {
3030
if (!stats)
3131
return message.channel.send(`\`${args[0]}\` is an invalid server!`);
3232
const statsembed = new MessageEmbed()
33-
.setAuthor(message.guild.name, message.guild.iconURL())
33+
.setAuthor({
34+
name: message.guild.name,
35+
iconURL: message.guild.iconURL(),
36+
})
3437
.setColor(client.config.embed.color)
3538
.setFooter(client.config.embed.footer);
36-
statsembed.addField("Rockets launched", stats.rocketLaunches);
39+
statsembed.addField("Rockets launched", stats.rocketLaunches.toString());
3740

3841
// TODO: add in again when the DB wrapper has the option
3942
// const research = stats.completedResearch?.reduce(
@@ -58,7 +61,9 @@ const StatsS: Command<Message> = {
5861
{ name: "Evolution", value: evolution },
5962
{ name: "Time", value: time }
6063
);
61-
return message.channel.send(statsembed);
64+
return message.channel.send({
65+
embeds: [statsembed],
66+
});
6267
},
6368
};
6469

0 commit comments

Comments
 (0)