Skip to content

Commit

Permalink
3.6 update (#12)
Browse files Browse the repository at this point in the history
* 3.6-pre01

* Handled all promises like a boss

* 3.6
  • Loading branch information
KifoPL authored May 14, 2021
1 parent e3e9166 commit de0df21
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 101 deletions.
2 changes: 1 addition & 1 deletion commands/fun/cringe.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ module.exports = {
}
}
embedreply.setDescription(reply);
message.channel.send(userping, embedreply).catch();
message.channel.send(userping, embedreply).catch(() => {});
},
};
201 changes: 181 additions & 20 deletions commands/utility/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ module.exports = {
//This is for timestamps
const ms = require(`ms`);
const fs = require("fs");
//for debugging, uncomment to resolve paths
//const path = require("path");

function place(number) {
if (number % 10 == 1) return `st`;
if (number % 10 == 2) return "nd";
if (number % 10 == 3) return "rd";
if (number % 10 == 1 && number % 100 != 11) return `st`;
if (number % 10 == 2 && number % 100 != 12) return "nd";
if (number % 10 == 3 && number % 100 != 13) return "rd";
else return "th";
}

Expand All @@ -21,7 +23,7 @@ module.exports = {
"you can only run this command on the server."
);
if (args[1] != undefined) return message.reply("too many arguments!");
message.channel.startTyping().catch();
message.channel.startTyping().catch(() => {});
const newEmbed = new Discord.MessageEmbed();
let time = new Date(Date.now());
let guildcount = 0;
Expand All @@ -31,6 +33,7 @@ module.exports = {
});
let serverrolecount = 0;
await message.guild.roles.cache.each(() => serverrolecount++);
let entity;

//SERVER STATS
if (args[0] == undefined) {
Expand All @@ -43,19 +46,37 @@ module.exports = {
let channelvoicecount = 0;
let channeltextcount = 0;
let channelcategorycount = 0;
let channelnewscount = 0;

var fileContent = `User ID\tUser name\tNickname\n`;

await message.guild.members.cache.each((member) => {
if (member.user.bot) botcount++;
if (member.premiumSinceTimestamp != undefined) boostcount++;
fileContent += `${member.id}\t${member.user.username}\t${member.nickname ?? ""}\n`
});
await message.guild.members.cache
.filter(
(member) =>
member.presence.status != "offline" && !member.user.bot
)
.each(() => onlinecount++);
await message.guild.members.cache.each((member) => {
if (member.premiumSinceTimestamp != undefined) boostcount++;

//const ChannelCollection = new Discord.Collection();
await message.guild.channels.cache.each((channel) => {
channelcount++;
// if (ChannelCollection.has(channel.type))
// {
// ChannelCollection.set(channel.type, ChannelCollection.get(channel.type) + 1)
// }
// else
// {
// ChannelCollection.set(channel.type, 1);
// }
});
await message.guild.channels.cache.each(() => channelcount++);
// ChannelCollection.each((value, key) => {
// console.log(`${key}: ${value}`)
// })
await message.guild.channels.cache
.filter((channel) => channel.type == "voice")
.each(() => channelvoicecount++);
Expand All @@ -65,6 +86,12 @@ module.exports = {
await message.guild.channels.cache
.filter((channel) => channel.type == "category")
.each(() => channelcategorycount++);
await message.guild.channels.cache
.filter((channel) => channel.type == "news")
.each(() => channelnewscount++);

fs.writeFileSync(`./${message.guild.id} members.txt`, fileContent, () => {});
//console.log(`${path.resolve(`${message.guild.id}members.txt`)}`);

let servertime = time.getTime() - message.guild.createdAt.getTime();
newEmbed
Expand Down Expand Up @@ -140,22 +167,21 @@ module.exports = {
},
{
name: `Channels`,
value: `<:voice:823658022684721164> ${channelvoicecount} voice channels, <:textchannel:823658022849085512> ${channeltextcount} text channels, <:category:823658022706217011> ${channelcategorycount} categories, Total: ${channelcount}.`,
value: `<:voice:823658022684721164> ${channelvoicecount} voice channel${channelvoicecount != 1 ? "s" : ""}, <:textchannel:823658022849085512> ${channeltextcount} text channel${channeltextcount != 1 ? "s" : ""}, <:categoryNEW:842672130420506625> ${channelcategorycount} categor${channelcategorycount != 1 ? "ies" : "y"}, <:announcement:842672130587754506> ${channelnewscount} news channel${channelnewscount != 1 ? "s" : ""}, Total: ${channelcount}.`,
},
// {name: `\u200B`, value: `\u200B`},
{
name: "More",
value:
"❗ If you want this command to have more stats, reach out to bot developer (KifoPL#3358, <@289119054130839552>)!",
}
);
)
.attachFiles([{attachment: `./${message.guild.id} members.txt`, name: `${message.guild.name} members.txt`}]);
} else {
//NOT SERVER STATS (user, bot, role, channel)
let entity;

let whatami = `assign to either "user | bot | role | channel | not found"`;

//someday fix it, possibly with "findit" npm
const folder = "fun";
const contents = fs.readFileSync(`././commandList.json`);
var jsonCmdList = JSON.parse(contents);

Expand Down Expand Up @@ -218,14 +244,19 @@ module.exports = {
let usertime = time.getTime() - entity.user.createdAt.getTime();
let membertime = time.getTime() - entity.joinedAt.getTime();
let rolecount = 0;
let fileContent = `Role ID\tRole name\n`
let statusicon;
if (
entity.presence.status == "online" ||
entity.presence.status == "idle"
)
statusicon = "<:online:823658022974521414>";
else statusicon = "<:offline:823658022957613076>";
await entity.roles.cache.each((role) => rolecount++);
await entity.roles.cache.each((role) => {

fileContent += `${role.id}\t${role.name}\n`
rolecount++
});

const ppfield = await ppcmd.execute(
message,
Expand All @@ -246,6 +277,9 @@ module.exports = {
Discord,
true
);

fs.writeFileSync(`./${entity.id} roles.txt`, fileContent, () => {});

newEmbed
.setColor("a039a0")
.setTitle(`${entity.displayName} stats:`)
Expand Down Expand Up @@ -356,21 +390,26 @@ module.exports = {
value:
"❗ If you want this command to have more stats, reach out to bot developer (KifoPL#3358, <@289119054130839552>)!",
}
);
)
.attachFiles([{attachment: `./${entity.id} roles.txt`, name: `${entity.id} roles.txt`}]);
}
//BOT STATS
else if (whatami == "bot") {
let usertime = time.getTime() - entity.user.createdAt.getTime();
let membertime = time.getTime() - entity.joinedAt.getTime();
let rolecount = 0;
let statusicon;
let fileContent = `Role ID\tRole name\n`
if (
entity.presence.status == "online" ||
entity.presence.status == "idle"
)
statusicon = "<:online:823658022974521414>";
else statusicon = "<:offline:823658022957613076>";
await entity.roles.cache.each((role) => rolecount++);
await entity.roles.cache.each((role) => {
rolecount++
fileContent += `${role.id}\t${role.name}\n`
});
const ppfield = await ppcmd.execute(
message,
args,
Expand All @@ -391,6 +430,8 @@ module.exports = {
true
);

fs.writeFileSync(`./${entity.id} roles.txt`, fileContent, () => {});

newEmbed
.setColor("a039a0")
.setTitle(`${entity.displayName} stats:`)
Expand Down Expand Up @@ -430,7 +471,7 @@ module.exports = {
entity.joinedAt.getTime() -
entity.user.createdAt.getTime(),
{ long: true }
)} after bot creation).`
)} after server creation).`
)
.addFields(
{
Expand Down Expand Up @@ -487,20 +528,27 @@ module.exports = {
value:
"❗ If you want this command to have more stats, reach out to bot developer (KifoPL#3358, <@289119054130839552>)!",
}
);
)
.attachFiles([{attachment: `./${entity.id} roles.txt`, name: `${entity.id} roles.txt`}]);
}
//ROLE STATS
else if (whatami == "role") {
let rolecreationAt =
time.getTime() - entity.createdAt.getTime();
let perms = entity.permissions;
let membercount = 0;
await entity.members.each(() => membercount++);
var fileContent = `User ID\tUser name\tNickname\n`;
await entity.members.each((member) => {
membercount++
fileContent += `${member.id}\t${member.user.username}\t${member.nickname ?? ""}\n`;
});
let strperms = "";
await perms.toArray().forEach(function (item, index, array) {
strperms += `${item}\n`;
});

fs.writeFileSync(`./${entity.id} members.txt`, fileContent, () => {});

newEmbed
.setColor("a039a0")
.setTitle(`${entity.name} stats:`)
Expand Down Expand Up @@ -576,15 +624,128 @@ module.exports = {
value:
"❗ If you want this command to have more stats, reach out to bot developer (KifoPL#3358, <@289119054130839552>)!",
}
);
)
.attachFiles([{attachment: `./${entity.id} members.txt`, name: `${message.id} members.txt`}]);
}
//CHANNEL STATS --- NOT YET IMPLEMENTED
else if (whatami == "channel") {

message.channel.stopTyping(true);
return message.reply("channel stats will be implemented one day.");

//TODO FINISH THIS
type = entity.type;
emote = "";
if (type == "text") emote = `<:textchannel:823658022849085512>`;
else if (type == "category") emote = `<:categoryNEW:842672130420506625>`;
else if (type == "voice") emote = `<:voice:823658022684721164>`;
else if (type == "news") emote = `<:announcement:842672130587754506>`;
else return message.reply("unsupported channel type! Reach out to KifoPL#3358 to notify him of the error.");

let channelage = time.getTime() - entity.createdAt.getTime();

newEmbed
.setColor("a039a0")
.setTitle(`${entity.name} stats:`)
.setDescription(
`${emote} ${type == "text" || type == "news" ? entity.topic : ""}`
)
.setAuthor(
"Kifo Clanker™, by KifoPL#3358",
message.guild.me?.user?.avatarURL({
format: "png",
dynamic: true,
size: 64,
}),
"https://github.com/KifoPL/kifo-clanker/"
)
.setFooter(
`Channel created at: ${entity.createdAt.toUTCString()}, ${ms(
entity.createdAt.getTime() -
entity.guild.createdAt.getTime(),
{ long: true }
)} after server creation.\nIt is ${ms(channelage, {
long: true,
})} old.`
)
.addFields(
{
name: `Roles`,
value: `<:role:823658022948700240> ${
rolecount != 1
? `${
rolecount - 1
} roles, highest role is ${
entity.roles?.highest?.name
} (${
-entity.roles?.highest.comparePositionTo(
message.guild.roles.highest
) + 1
}${place(
-entity.roles?.highest.comparePositionTo(
message.guild.roles.highest
) + 1
)} out of ${serverrolecount} server roles), ${
entity.roles?.hoist?.name ==
undefined
? `not hoisted`
: `\nhoisted as <:hoist:823907804141322311> ${entity.roles?.hoist?.name}`
}.`
: `This bot has no roles yet.`
}`,
},
{
name: `Status`,
value: `${statusicon} Bot is currently **${entity.presence.status}**.`,
},
{
name: `Interesting stats:`,
value: `(They're seriously interesting, though!)`,
},
{
name: `IQ level: ${iqfield.name}`,
value: iqfield.value,
inline: true,
},
{
name: `PP: ${ppfield.name}`,
value: ppfield.value,
inline: true,
},
{
name: `Gayness level: ${howgayfield.name}`,
value: howgayfield.value,
inline: false,
},
//{name: "Also:", value: `You can check your own stats with "!kifo stats me", or someone else's stats by ${this.usage}`},
{
name: "More",
value:
"❗ If you want this command to have more stats, reach out to bot developer (KifoPL#3358, <@289119054130839552>)!",
}
)


}
}
message.channel.send(newEmbed).catch();
await message.channel.send(newEmbed).catch(err => {
console.error(err);
});
message.channel.stopTyping(true);
try
{
fs.unlink(`./${message.guild.id} members.txt`, () => {}).catch(() => {});
}
catch (err) {}
try
{
fs.unlink(`./${entity.id} members.txt`, () => {}).catch(() => {});
}
catch (err) {}
try
{
fs.unlink(`./${entity.id} roles.txt`, () => {}).catch(() => {});
}
catch (err) {}
},
};
16 changes: 10 additions & 6 deletions commands/utility/top.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ module.exports = {
);
if (args[4] != undefined)
return message.reply(`too many arguments! Use ${this.usage}`);
// let ping = false;
// if (args[4] != undefined) {
// if (!(message.member.permissions.has("ADMINISTRATOR"))) return message.reply("sorry, only Admins can ping authors."); else if (args[4] == "ping") ping = true; else return message.reply("type **ping** if you want to ping authors. If not, end the command at emote.");
// }

function place(number) {
if (number % 10 == 1 && number % 100 != 11) return `st`;
if (number % 10 == 2 && number % 100 != 12) return "nd";
if (number % 10 == 3 && number % 100 != 13) return "rd";
else return "th";
}

let now = Date.now();
let whichchannel = message.channel.guild.channels.cache.find(
Expand Down Expand Up @@ -152,9 +155,10 @@ module.exports = {

message.channel.startTyping().catch();
newEmbed.setTitle(
"**Top " +
"**" +
ii +
"** by **" +
place(ii) +
"** place by **" +
chmessages[i].author.username +
"** with **" +
chmessages[i].reactions.resolve(key).count +
Expand Down
Loading

0 comments on commit de0df21

Please sign in to comment.