Compare commits
43 changed files with 1644 additions and 3033 deletions
7
.github/workflows/CI.yml
vendored
7
.github/workflows/CI.yml
vendored
|
|
@ -2,9 +2,6 @@ name: CI
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
CI:
|
CI:
|
||||||
runs-on: node
|
runs-on: node
|
||||||
|
|
@ -16,6 +13,6 @@ jobs:
|
||||||
with:
|
with:
|
||||||
node-version: 'latest'
|
node-version: 'latest'
|
||||||
- name: install dependencies
|
- name: install dependencies
|
||||||
run: npm ci
|
run: npm install
|
||||||
- name: run tests
|
- name: run tests
|
||||||
run: npm test
|
run: npm test
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const savePresence = require("../../util/savePresence");
|
|
||||||
const setPresence = require("../../util/setPresence");
|
const setPresence = require("../../util/setPresence");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -11,20 +10,12 @@ module.exports = {
|
||||||
,"Updates once a minute if custom variables are used."
|
,"Updates once a minute if custom variables are used."
|
||||||
,""
|
,""
|
||||||
,"Custom Variables:"
|
,"Custom Variables:"
|
||||||
,"${guilds},${prefix},${uptime},{members}"],
|
,"${guilds},${prefix},${uptime}"],
|
||||||
admin: true,
|
admin: true,
|
||||||
execute({message, client, args, prefix}) {
|
execute({message, client, args, globalPrefix}) {
|
||||||
let forceUpdate = false;
|
const savePresence = require("../../util/savePresence");
|
||||||
if(args.length > 1 && args[0] === "force") {
|
|
||||||
forceUpdate = true;
|
|
||||||
args.shift();
|
|
||||||
}
|
|
||||||
if(args.length < 1){
|
|
||||||
message.channel.send(`You need at least two arguments for this command, see \`${prefix}help setpresence\``)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let presenceType = args[0].toLocaleUpperCase();
|
let presenceType = args[0].toLocaleUpperCase();
|
||||||
let sendText = "Presence has been set.";
|
let sendText = "Updated presence";
|
||||||
|
|
||||||
switch (presenceType) {
|
switch (presenceType) {
|
||||||
case "PLAY":
|
case "PLAY":
|
||||||
|
|
@ -55,11 +46,8 @@ module.exports = {
|
||||||
const firstArg = args[0].length + 1;
|
const firstArg = args[0].length + 1;
|
||||||
let temp = args.join(" ");
|
let temp = args.join(" ");
|
||||||
let presenceText = temp.slice(firstArg, temp.length)
|
let presenceText = temp.slice(firstArg, temp.length)
|
||||||
|
setPresence({presenceText: presenceText,presenceType: presenceType, client: client, globalPrefix: globalPrefix});
|
||||||
savePresence(presenceType, presenceText, client);
|
savePresence(presenceType, presenceText, client);
|
||||||
if(forceUpdate)
|
|
||||||
setPresence({presenceText, presenceType, client})
|
|
||||||
else
|
|
||||||
sendText = `${sendText} It will update <t:${Math.floor((client.lastPresenceUpdate + 60000) / 1000)}:R>`
|
|
||||||
}
|
}
|
||||||
message.channel.send(sendText);
|
message.channel.send(sendText);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
const calculateReloaded = require("../../util/calculateReloaded");
|
const calculateReloaded = require("../../util/calculateReloaded");
|
||||||
const executeCommand = require("../../util/executeCommand");
|
|
||||||
const reloadCommands = require("../../util/reloadCommands");
|
const reloadCommands = require("../../util/reloadCommands");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -28,12 +27,10 @@ module.exports = {
|
||||||
let commitCount = stdout.split(/\r\n|\r|\n/).length - 1
|
let commitCount = stdout.split(/\r\n|\r|\n/).length - 1
|
||||||
sendText = `${sendText}\n\nLatest commits (${commitCount}):\n${stdout}`
|
sendText = `${sendText}\n\nLatest commits (${commitCount}):\n${stdout}`
|
||||||
if(sendText.length >= 2000){
|
if(sendText.length >= 2000){
|
||||||
sendText = sendText.slice(1955)
|
sendText.slice(1955)
|
||||||
sendText = `${sendText}\n... Message is too long to show everything`
|
sendText = `${sendText}\n... Message is too long to show everything`
|
||||||
}
|
}
|
||||||
message.channel.send(sendText)
|
message.channel.send(sendText)
|
||||||
const githash = executeCommand(`git`, ["rev-parse", "--short", "HEAD"]);
|
|
||||||
client.githash = githash.error ? "N/A" : githash.output;
|
|
||||||
if (err) console.log(stderr)
|
if (err) console.log(stderr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,106 +2,55 @@ const sqlite3 = require('sqlite3').verbose();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'whitelist',
|
name: 'whitelist',
|
||||||
description: 'Whitelist a command in a specific server, or for a user.',
|
description: 'Whitelist a command in a specific server.',
|
||||||
admin: true,
|
admin: true,
|
||||||
async execute({message, args, prefix, client}) {
|
async execute({message, args, prefix, client}) {
|
||||||
if(args.length < 3){
|
if(args.length < 2){
|
||||||
message.channel.send(`You need to supply the command and guild that you want to whitelist\n\`${prefix}whitelist <user|guild> <command> <user_id|guild_id>\``);
|
message.channel.send(`You need to supply the command and channel that you want to whitelist\n\`${prefix}whitelist <command> <server_id>\``);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let option = args[0];
|
let command = args[0];
|
||||||
let command = args[1];
|
let guild = args[1];
|
||||||
let guildOrUser = args[2];
|
if(guild === "this") guild = message.guild.id;
|
||||||
|
// TODO: Add ability to remove server from whitelist.
|
||||||
if(option === "guild" || option === "server"){
|
const whitelistedCommands = client.whitelist.get(guild);
|
||||||
if(guildOrUser === "this") guildOrUser = message.guild.id;
|
if(whitelistedCommands && whitelistedCommands.includes(command)){
|
||||||
const whitelistedCommands = client.whitelist.guild.get(guildOrUser);
|
message.channel.send("Command is already whitelisted in that server.")
|
||||||
if(whitelistedCommands && whitelistedCommands.includes(command)){
|
|
||||||
message.channel.send("Command is already whitelisted in that server.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// TODO: First check if the bot has access to that guild before whitelisting.
|
|
||||||
const databasePath = 'data/database.db'
|
|
||||||
const db = new sqlite3.Database(databasePath)
|
|
||||||
let err = false;
|
|
||||||
await new Promise((resolve, reject)=>{
|
|
||||||
db.run(`INSERT INTO guild_whitelist (
|
|
||||||
guildId,
|
|
||||||
command,
|
|
||||||
dateAdded
|
|
||||||
) VALUES (?, ?, ?)`,
|
|
||||||
[
|
|
||||||
guildOrUser,
|
|
||||||
command,
|
|
||||||
new Date().getTime()
|
|
||||||
], function (error) {
|
|
||||||
if (error) {
|
|
||||||
console.error(error);
|
|
||||||
err = true;
|
|
||||||
resolve();
|
|
||||||
}else{
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
db.close();
|
|
||||||
if(!err){
|
|
||||||
if(whitelistedCommands){
|
|
||||||
whitelistedCommands.push(command);
|
|
||||||
client.whitelist.guild.set(guildOrUser, whitelistedCommands);
|
|
||||||
}else {
|
|
||||||
client.whitelist.guild.set(guildOrUser, command);
|
|
||||||
}
|
|
||||||
message.channel.send(`"${command}" has been whitelisted in that server.`)
|
|
||||||
|
|
||||||
} else message.channel.send("Could not whitelist the server with that command. Check the logs.")
|
|
||||||
return;
|
|
||||||
}else if (option === "user"){
|
|
||||||
const whitelistedCommands = client.whitelist.user.get(guildOrUser);
|
|
||||||
if(whitelistedCommands && whitelistedCommands.includes(command)){
|
|
||||||
message.channel.send("Command is already whitelisted for that user.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const databasePath = 'data/database.db'
|
|
||||||
const db = new sqlite3.Database(databasePath)
|
|
||||||
let err = false;
|
|
||||||
await new Promise((resolve, reject)=>{
|
|
||||||
db.run(`INSERT INTO user_whitelist (
|
|
||||||
userId,
|
|
||||||
command,
|
|
||||||
dateAdded
|
|
||||||
) VALUES (?, ?, ?)`,
|
|
||||||
[
|
|
||||||
guildOrUser,
|
|
||||||
command,
|
|
||||||
new Date().getTime()
|
|
||||||
], function (error) {
|
|
||||||
if (error) {
|
|
||||||
console.error(error);
|
|
||||||
err = true;
|
|
||||||
resolve();
|
|
||||||
}else{
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
db.close();
|
|
||||||
if(!err){
|
|
||||||
if(whitelistedCommands){
|
|
||||||
whitelistedCommands.push(command);
|
|
||||||
client.whitelist.user.set(guildOrUser, whitelistedCommands);
|
|
||||||
}else {
|
|
||||||
client.whitelist.user.set(guildOrUser, command);
|
|
||||||
}
|
|
||||||
message.channel.send(`"${command}" has been whitelisted for ${guildOrUser}.`)
|
|
||||||
|
|
||||||
} else message.channel.send("Could not whitelist the server with that command. Check the logs.")
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO: First check if the bot has access to that guild before whitelisting.
|
||||||
|
const databasePath = 'data/database.db'
|
||||||
|
const db = new sqlite3.Database(databasePath)
|
||||||
|
let err = false;
|
||||||
|
await new Promise((resolve, reject)=>{
|
||||||
|
db.run(`INSERT INTO whitelist (
|
||||||
|
serverId,
|
||||||
|
command,
|
||||||
|
dateAdded
|
||||||
|
) VALUES (?, ?, ?)`,
|
||||||
|
[
|
||||||
|
guild,
|
||||||
|
command,
|
||||||
|
new Date().getTime()
|
||||||
|
], function (error) {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
err = true;
|
||||||
|
resolve();
|
||||||
|
}else{
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
if(!err){
|
||||||
|
if(whitelistedCommands){
|
||||||
|
whitelistedCommands.push(command);
|
||||||
|
client.whitelist.set(guild, whitelistedCommands);
|
||||||
|
}else {
|
||||||
|
client.whitelist.set(guild, command);
|
||||||
|
}
|
||||||
|
message.channel.send("Command has been whitelisted in that server.")
|
||||||
|
|
||||||
|
} else message.channel.send("Could not whitelist the server with that command. Check the logs.")
|
||||||
|
|
||||||
// TODO: Add ability to remove server from whitelist.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const {EmbedBuilder} = require('discord.js');
|
const {EmbedBuilder} = require('discord.js');
|
||||||
const getCreationDate = require('../../util/getCreationDate');
|
const getCreationDate = require('../../util/getCreationDate');
|
||||||
const getGuildInfo = require('../../util/getGuildInfo');
|
const getGuildCount = require('../../util/getGuildCount');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -8,28 +8,15 @@ module.exports = {
|
||||||
name: 'botinfo',
|
name: 'botinfo',
|
||||||
description: 'Shows information about the bot',
|
description: 'Shows information about the bot',
|
||||||
execute({message, client, prefix}) {
|
execute({message, client, prefix}) {
|
||||||
let guildInfo = getGuildInfo(client)
|
let guildCount = getGuildCount(client)
|
||||||
let descriptionArr = [`Name: ${client.user.username}`,
|
|
||||||
`Prefix: ${prefix}`,
|
|
||||||
`Total Servers: ${guildInfo.guildCount}`,
|
|
||||||
`Total Members: ${guildInfo.totalMembers} (${guildInfo.uniqueMemberCount} unique)`,
|
|
||||||
`Total Commands: ${client.commands.size}`,
|
|
||||||
`Creation Date: ${getCreationDate(client)}`,
|
|
||||||
`Source: [Click Here](https://github.com/SileNce5k/discord_bot)`,
|
|
||||||
`Current Version: ${client.githash}`
|
|
||||||
]
|
|
||||||
|
|
||||||
let description = "";
|
|
||||||
descriptionArr.forEach(desc => {
|
|
||||||
description += `${desc}\n`;
|
|
||||||
})
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(15780145)
|
.setColor(15780145)
|
||||||
.setTitle("Information about bot")
|
.setTitle("Information about bot")
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setAuthor({name: client.user.username, iconURL: client.user.avatarURL({ format: 'png', dynamic: true, size: 2048 })})
|
.setAuthor({name: client.user.username, iconURL: client.user.avatarURL({ format: 'png', dynamic: true, size: 2048 })})
|
||||||
.setDescription(description)
|
.addFields({
|
||||||
|
name: "General info", value: `Name: ${client.user.username}\nPrefix: ${prefix}\nTotal Servers: ${guildCount}\nTotal Commands: ${client.commands.size}\nCreation Date: ${getCreationDate(client)}\nSource: [Click Here](https://github.com/SileNce5k/discord_bot)`,
|
||||||
|
},)
|
||||||
|
|
||||||
message.channel.send({embeds :[embed]})
|
message.channel.send({embeds :[embed]})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ module.exports = {
|
||||||
description: 'Returns guild names',
|
description: 'Returns guild names',
|
||||||
admin: true,
|
admin: true,
|
||||||
execute({message, client}) {
|
execute({message, client}) {
|
||||||
let guildNames = client.guilds.cache
|
let guildNames = "";
|
||||||
.sort((a, b) => b.memberCount - a.memberCount)
|
client.guilds.cache.each(guild => {
|
||||||
.map(guild => `${guild.name} (${guild.memberCount} members)`)
|
guildNames = guildNames + guild.name + "\n";
|
||||||
.join("\n");
|
});
|
||||||
message.channel.send(guildNames)
|
message.channel.send(guildNames)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -13,6 +13,7 @@ module.exports = {
|
||||||
execute({ message, args, prefix, client }) {
|
execute({ message, args, prefix, client }) {
|
||||||
let commands = ""
|
let commands = ""
|
||||||
let commandFiles = getSubdirFiles('commands/')
|
let commandFiles = getSubdirFiles('commands/')
|
||||||
|
let x = false;
|
||||||
let fieldName = `Page [[page]]/${Math.round(client.commands.size / 10)}`;
|
let fieldName = `Page [[page]]/${Math.round(client.commands.size / 10)}`;
|
||||||
let iteration = 0;
|
let iteration = 0;
|
||||||
let num_in_args = false;
|
let num_in_args = false;
|
||||||
|
|
@ -31,6 +32,7 @@ module.exports = {
|
||||||
fieldName = fieldName.replace("[[page]]", page);
|
fieldName = fieldName.replace("[[page]]", page);
|
||||||
const max_commands = iteration + 10;
|
const max_commands = iteration + 10;
|
||||||
|
|
||||||
|
if (x) return;
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(15780145)
|
.setColor(15780145)
|
||||||
|
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
// Code is taken from https://github.com/stphnduvall/mcstatus/blob/master/src/index.ts
|
|
||||||
// and converted to pure js.
|
|
||||||
|
|
||||||
const net = require('net')
|
|
||||||
const { EmbedBuilder } = require('discord.js');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'mc',
|
|
||||||
description: 'get minecraft server information',
|
|
||||||
hidden: true,
|
|
||||||
needsWhitelist: true,
|
|
||||||
async execute({ message, args }) {
|
|
||||||
let host = "";
|
|
||||||
let port = 25565;
|
|
||||||
if (args[0]) host = args[0];
|
|
||||||
|
|
||||||
if (host.includes(":")) {
|
|
||||||
port = host.replace(/.+(?:\:)/g, "");
|
|
||||||
host = host.match(/.+(?:\:)/g, "")[0].replace(":", "");
|
|
||||||
}
|
|
||||||
if(host === "") return message.channel.send("No host provided")
|
|
||||||
let info = await getMinecraftServerInfo(host, port);
|
|
||||||
if (info) {
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
embed.setColor("#ee7939")
|
|
||||||
embed.setTimestamp()
|
|
||||||
embed.addFields(
|
|
||||||
{ name: "ping", value: info.ping.toString(), inline: false },
|
|
||||||
{ name: "Player Count", value: info.playercount.toString(), inline: false },
|
|
||||||
{ name: "Max Players", value: info.maxPlayers.toString(), inline: false },
|
|
||||||
{ name: "MOTD", value: info.motd, inline: false },
|
|
||||||
)
|
|
||||||
|
|
||||||
message.channel.send({ embeds: [embed] });
|
|
||||||
} else {
|
|
||||||
message.channel.send("Something went wrong\nThe minecraft server is likely not reachable from the discord bot")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function getMinecraftServerInfo(host, port = 25565) {
|
|
||||||
let serverInfo = {
|
|
||||||
ping: undefined,
|
|
||||||
maxPlayers: undefined,
|
|
||||||
version: undefined,
|
|
||||||
playercount: undefined,
|
|
||||||
motd: undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
let startTime = new Date();
|
|
||||||
let data;
|
|
||||||
let ping;
|
|
||||||
serverInfo = await new Promise((resolve) => {
|
|
||||||
const client = net.connect({ host, port }, () => {
|
|
||||||
ping = Math.round(new Date().getMilliseconds() - startTime.getMilliseconds());
|
|
||||||
|
|
||||||
let buff = Buffer.from([0xFE, 0x01]);
|
|
||||||
client.write(buff);
|
|
||||||
|
|
||||||
})
|
|
||||||
let error = false;
|
|
||||||
client.on('data', (d) => {
|
|
||||||
data = d.toString()
|
|
||||||
client.destroy();
|
|
||||||
|
|
||||||
})
|
|
||||||
client.once('error', (error) => {
|
|
||||||
console.error(error)
|
|
||||||
error = true;
|
|
||||||
})
|
|
||||||
client.once('connectionAttemptFailed', (ip) => {
|
|
||||||
console.error("in attempt failed")
|
|
||||||
error = true;
|
|
||||||
})
|
|
||||||
|
|
||||||
client.once('connectionAttemptTimeout', (ip) => {
|
|
||||||
console.error("in attempt timeout")
|
|
||||||
error = true;
|
|
||||||
})
|
|
||||||
client.on('close', () => {
|
|
||||||
if (!error) {
|
|
||||||
let _serverInfo = data?.split('\x00\x00\x00');
|
|
||||||
|
|
||||||
if (!_serverInfo) {
|
|
||||||
console.log("Something went wrong.")
|
|
||||||
resolve(serverInfo)
|
|
||||||
}
|
|
||||||
serverInfo.version = _serverInfo[2].replace(/\u0000/g, '')
|
|
||||||
serverInfo.motd = _serverInfo[3].replace(/\u0000/g, '')
|
|
||||||
serverInfo.playercount = Number(_serverInfo[4].replace(/\u0000/g, ''))
|
|
||||||
serverInfo.maxPlayers = Number(_serverInfo[5].replace(/\u0000/g, ''))
|
|
||||||
serverInfo.ping = Number(ping)
|
|
||||||
resolve(serverInfo)
|
|
||||||
} else {
|
|
||||||
resolve(0)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
return serverInfo
|
|
||||||
}
|
|
||||||
|
|
@ -16,9 +16,9 @@ module.exports = {
|
||||||
let user = message.guild.members.cache.get(info);
|
let user = message.guild.members.cache.get(info);
|
||||||
let guildPfp = user.avatarURL({format: 'png', dynamic: true, size: 4096});
|
let guildPfp = user.avatarURL({format: 'png', dynamic: true, size: 4096});
|
||||||
let globalPfp = user.user.avatarURL({format: 'png', dynamic: true, size: 4096});
|
let globalPfp = user.user.avatarURL({format: 'png', dynamic: true, size: 4096});
|
||||||
let sendText = `${globalPfp}`;
|
let sendText = `Global pfp:\n${globalPfp}`;
|
||||||
if(guildPfp != null){
|
if(guildPfp != null){
|
||||||
sendText = `Global pfp${sendText}\nGuild pfp:\n${guildPfp}`;
|
sendText = `${sendText}\nGuild pfp:\n${guildPfp}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.channel.send(sendText)
|
message.channel.send(sendText)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ module.exports = {
|
||||||
{name: "Server Name", value: message.guild.name, inline: false},
|
{name: "Server Name", value: message.guild.name, inline: false},
|
||||||
{name: "Created", value: convertDateToISOString(message.guild.createdAt), inline: false},
|
{name: "Created", value: convertDateToISOString(message.guild.createdAt), inline: false},
|
||||||
{name: "Members", value: message.guild.memberCount.toString(), inline: false},
|
{name: "Members", value: message.guild.memberCount.toString(), inline: false},
|
||||||
{name: "Channels", value: message.guild.channels.channelCountWithoutThreads.toString(), inline: false},
|
|
||||||
|
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
|
||||||
48
commands/misc/chat.js
Normal file
48
commands/misc/chat.js
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
require("dotenv").config();
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'chat',
|
||||||
|
description: 'A chat command that uses an LLM to answer your prompts (server must be whitelisted)',
|
||||||
|
needsWhitelist: true,
|
||||||
|
async execute({ message, args }) {
|
||||||
|
|
||||||
|
if(args.length === 0){
|
||||||
|
message.channel.send("You have to set your prompt in the arguments");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const prompt = args.join(" ");
|
||||||
|
let answer = "";
|
||||||
|
const initialMessage = await message.channel.send("Generating response... This may take a moment.")
|
||||||
|
message.channel.sendTyping();
|
||||||
|
// TODO: More configuration. Have a basic setup but allow setting system prompt, max tokens and model.
|
||||||
|
await fetch(`https://openrouter.ai/api/v1/chat/completions`, {
|
||||||
|
method: `POST`,
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${process.env.OPENROUTER_API_KEY}`,
|
||||||
|
"Content-Type": `application/json`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
"model": `deepseek/deepseek-chat-v3-0324:free`,
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"role": `user`,
|
||||||
|
"content": prompt
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"max_tokens": 250
|
||||||
|
})
|
||||||
|
}).then(response => response.json()).then(data => {
|
||||||
|
answer = data.choices[0].message.content;
|
||||||
|
}).catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
if(answer.length > 0){
|
||||||
|
if(answer.length > 1999){
|
||||||
|
initialMessage.edit("Unfortunately the length of the message was longer than what discord allows.")
|
||||||
|
}
|
||||||
|
initialMessage.edit(answer)
|
||||||
|
}else {
|
||||||
|
initialMessage.edit("Something went wrong. The owner should check the console.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs')
|
|
||||||
|
|
||||||
const executeCommand = require('../../util/executeCommand');
|
|
||||||
module.exports = {
|
|
||||||
name: 'dl',
|
|
||||||
description: 'Download a video',
|
|
||||||
moreHelp: [
|
|
||||||
"Usage: <prefix>dl <url>"
|
|
||||||
],
|
|
||||||
async execute({message, args}) {
|
|
||||||
const downloadsDir = path.resolve(process.cwd(), 'data', 'downloads', Date.now().toString());
|
|
||||||
const cookieFilepath = path.resolve(process.cwd(), 'data', 'cookies.txt')
|
|
||||||
if(!fs.existsSync(cookieFilepath)) {
|
|
||||||
message.channel.send("Some dependencies are needed for the command to work properly. Please let the bot's owner know.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fs.mkdirSync(downloadsDir, {recursive: true});
|
|
||||||
|
|
||||||
let url;
|
|
||||||
|
|
||||||
if(args.length > 0){
|
|
||||||
if(args[0].charAt(0) === '<' && args[0].charAt(args[0].length - 1) === '>'){
|
|
||||||
args[0] = args[0].slice(1, args[0].length - 1)
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
url = new URL(args[0]);
|
|
||||||
url = url.href;
|
|
||||||
} catch (error) {
|
|
||||||
this.cleanUp(downloadsDir);
|
|
||||||
message.channel.send("Could not parse the provided argument as a URL.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.cleanUp(downloadsDir);
|
|
||||||
return message.channel.send("You have to provide a URL in an argument.")
|
|
||||||
}
|
|
||||||
|
|
||||||
const originalMessage = await message.channel.send("Downloading video...")
|
|
||||||
|
|
||||||
if(executeCommand("yt-dlp", [url, "-P", downloadsDir, "--cookies", cookieFilepath]).error){
|
|
||||||
originalMessage.edit("An error occurred when downloading the video.");
|
|
||||||
this.cleanUp(downloadsDir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
let files = fs.readdirSync(downloadsDir);
|
|
||||||
if(files.length < 1) {
|
|
||||||
this.cleanUp(downloadsDir);
|
|
||||||
originalMessage.edit("Something went wrong when downloading the video.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const filename = files[0];
|
|
||||||
|
|
||||||
await originalMessage.edit({
|
|
||||||
content: null,
|
|
||||||
files: [{
|
|
||||||
attachment: path.resolve(downloadsDir, filename)
|
|
||||||
}]})
|
|
||||||
|
|
||||||
this.cleanUp(downloadsDir);
|
|
||||||
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
cleanUp(downloadsDir){
|
|
||||||
fs.rmSync(downloadsDir, {force: true, recursive: true});
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -9,7 +9,6 @@ const getTopArtists = require("../../util/lastfm/getTopArtists");
|
||||||
const getTopAlbums = require("../../util/lastfm/getTopAlbums");
|
const getTopAlbums = require("../../util/lastfm/getTopAlbums");
|
||||||
const {EmbedBuilder} = require('discord.js');
|
const {EmbedBuilder} = require('discord.js');
|
||||||
const getNickname = require('../../util/getNickname');
|
const getNickname = require('../../util/getNickname');
|
||||||
const isWhitelisted = require("../../util/isWhitelisted");
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'fm',
|
name: 'fm',
|
||||||
description: 'Last fm commands. See `<prefix>help fm` for more info.',
|
description: 'Last fm commands. See `<prefix>help fm` for more info.',
|
||||||
|
|
@ -17,8 +16,6 @@ module.exports = {
|
||||||
"They behave the same (for example: `<prefix>fmtt` and `<prefix>fm tt`)",
|
"They behave the same (for example: `<prefix>fmtt` and `<prefix>fm tt`)",
|
||||||
"Set username: `<prefix>fmset <lastfm_username>`",
|
"Set username: `<prefix>fmset <lastfm_username>`",
|
||||||
"Get current scrobble: `<prefix>fm`",
|
"Get current scrobble: `<prefix>fm`",
|
||||||
"Get top artists `<prefix>fmas`",
|
|
||||||
"Get top albums: `<prefix>fmabl`",
|
|
||||||
"Get top tracks: `<prefix>fmtt`",
|
"Get top tracks: `<prefix>fmtt`",
|
||||||
"Get album cover for current scrobble: `<prefix>fmcover`",
|
"Get album cover for current scrobble: `<prefix>fmcover`",
|
||||||
"Get a roast from an LLM using your top artists and albums: `<prefix>fmroast`"
|
"Get a roast from an LLM using your top artists and albums: `<prefix>fmroast`"
|
||||||
|
|
@ -37,31 +34,12 @@ module.exports = {
|
||||||
args.shift();
|
args.shift();
|
||||||
sendText = await getTopTracks(message.author.id, args, message.guild);
|
sendText = await getTopTracks(message.author.id, args, message.guild);
|
||||||
break;
|
break;
|
||||||
case "topalbums":
|
|
||||||
case "topalbum":
|
|
||||||
case "abl":
|
|
||||||
args.shift();
|
|
||||||
sendText = await getTopAlbums(message.author.id, args, message.guild)
|
|
||||||
break;
|
|
||||||
case "topartists":
|
|
||||||
case "topartist":
|
|
||||||
case "ta":
|
|
||||||
case "as":
|
|
||||||
args.shift();
|
|
||||||
sendText = await getTopArtists(message.author.id, args, message.guild);
|
|
||||||
break;
|
|
||||||
case "cover":
|
case "cover":
|
||||||
sendText = await getCurrentCover(message.author.id, message.guild);
|
sendText = await getCurrentCover(message.author.id, message.guild);
|
||||||
break;
|
break;
|
||||||
case "roast":
|
case "roast":
|
||||||
const commandName = "fmroast"
|
|
||||||
if(!isWhitelisted.isWhitelisted(commandName, client.whitelist, message.guild.id, message.author.id, isWhitelisted.whitelistTypes.EITHER)) {
|
|
||||||
message.channel.send("fmroast has not been whitelisted for you or this server.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let topArtists = await getTopArtists(message.author.id, ["yearly"], message.guild, true);
|
let topArtists = await getTopArtists(message.author.id, ["yearly"], message.guild, true);
|
||||||
let topAlbums = await getTopAlbums(message.author.id, ["yearly"], message.guild, true);
|
let topAlbums = await getTopAlbums(message.author.id, ["yearly"], message.guild, true);
|
||||||
message.channel.sendTyping();
|
|
||||||
let result = await roast(topArtists, topAlbums);
|
let result = await roast(topArtists, topAlbums);
|
||||||
|
|
||||||
let parse = parseMention(message.author.id, message.guild)
|
let parse = parseMention(message.author.id, message.guild)
|
||||||
|
|
@ -87,13 +65,11 @@ module.exports = {
|
||||||
if(sendText.embed != null){
|
if(sendText.embed != null){
|
||||||
let parse = parseMention(message.author.id, message.guild)
|
let parse = parseMention(message.author.id, message.guild)
|
||||||
let user = message.guild.members.cache.get(parse);
|
let user = message.guild.members.cache.get(parse);
|
||||||
if(!sendText.embed.data.color){
|
let roleColor = 15788778;
|
||||||
let roleColor = 15788778;
|
if (user.roles.color) {
|
||||||
if (user.roles.color) {
|
roleColor = user.roles.color.color;
|
||||||
roleColor = user.roles.color.color;
|
|
||||||
}
|
|
||||||
sendText.embed.setColor(roleColor);
|
|
||||||
}
|
}
|
||||||
|
sendText.embed.setColor(roleColor);
|
||||||
message.channel.send({embeds :[sendText.embed]})
|
message.channel.send({embeds :[sendText.embed]})
|
||||||
}else{
|
}else{
|
||||||
message.channel.send(sendText.text.replaceAll("<prefix>", prefix));
|
message.channel.send(sendText.text.replaceAll("<prefix>", prefix));
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'ig',
|
|
||||||
description: 'Replaces Instagram links with kkinstagram and deletes the original message',
|
|
||||||
execute({message, args}) {
|
|
||||||
const noUrlErr = "You need to provide an Instagram link to use this command."
|
|
||||||
if(args.length < 1) {
|
|
||||||
message.channel.send(noUrlErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let replacedLink = "";
|
|
||||||
const regex = /(?<=\/)(instagram)\.com/g
|
|
||||||
if(args[0].startsWith("https://") || args[0].startsWith("http://")){
|
|
||||||
replacedLink = args[0].replace(regex, "kkinstagram.com");
|
|
||||||
}
|
|
||||||
if(replacedLink.length === 0 || args[0] === replacedLink){
|
|
||||||
message.channel.send(noUrlErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
message.channel.send(replacedLink);
|
|
||||||
try{
|
|
||||||
message.delete()
|
|
||||||
}catch(err){
|
|
||||||
console.error(`${this.name}: An error occurred while trying to delete the original message.`)
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'ping',
|
name: 'ping',
|
||||||
description: 'Just ping.',
|
description: 'Just ping.',
|
||||||
async execute({message, client}) {
|
execute({message, client}) {
|
||||||
let apiLatency = client.ws.ping;
|
message.channel.send(`Pong.\n${client.ws.ping}ms`)
|
||||||
const time = process.hrtime.bigint();
|
|
||||||
let initialMessage = await message.channel.send(`Pong.`)
|
|
||||||
const diff = Number(process.hrtime.bigint() - time) * 1e-6;
|
|
||||||
initialMessage.edit(`Pong.\nAPI latency: ${apiLatency} ms\nMessage latency: ${diff.toFixed(0)} ms.`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
const setServerPrefix = require("../../util/setServerPrefix");
|
const setServerPrefix = require("../../util/setServerPrefix");
|
||||||
const { PermissionsBitField } = require('discord.js');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'prefix',
|
name: 'prefix',
|
||||||
description: 'Change the prefix of the bot in this server.',
|
description: 'Change the prefix of the bot in this server.',
|
||||||
execute({ message, client, args, prefix }) {
|
execute({ message, client, args, prefix }) {
|
||||||
if (!message.member.permissions.has(PermissionsBitField.Flags.ManageGuild)) {
|
if (!message.member.permissions.has('MANAGE_GUILD')) {
|
||||||
message.channel.send("You do not have sufficient permissions(MANAGE_GUILD) to change the prefix of this server.")
|
message.channel.send("You do not have sufficient permissions(MANAGE_GUILD) to change the prefix of this server.")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'say',
|
name: 'say',
|
||||||
description: 'Repeats arguments',
|
description: 'Repeats arguments',
|
||||||
admin: true,
|
|
||||||
execute({message, args}) {
|
execute({message, args}) {
|
||||||
|
|
||||||
if(args.length == 0)
|
if(args.length == 0)
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,16 @@ const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { writeFile } = require('node:fs/promises')
|
const { writeFile } = require('node:fs/promises')
|
||||||
const { Readable } = require('node:stream')
|
const { Readable } = require('node:stream')
|
||||||
const executeCommand = require('../../util/executeCommand');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'tdoss',
|
name: 'tdoss',
|
||||||
description: 'Combine picture with tdoss album cover template',
|
description: 'Combine picture with tdoss album cover template',
|
||||||
async execute({ message, args }) {
|
async execute({ message, args }) {
|
||||||
|
|
||||||
let tdossDir = path.resolve(process.cwd(), 'data', 'tdoss');
|
let dataDir = path.resolve(__dirname, '..', '..', 'data');
|
||||||
const tdossTemplate = path.resolve(process.cwd(), 'resources', 'tdoss_template.png');
|
const directory = path.resolve(dataDir, Math.floor(new Date).toString())
|
||||||
|
fs.mkdirSync(directory)
|
||||||
const directory = path.resolve(tdossDir, Math.floor(new Date).toString())
|
|
||||||
fs.mkdirSync(directory, {recursive: true})
|
|
||||||
|
|
||||||
let url = "";
|
let url = "";
|
||||||
if(message.attachments.size > 0){
|
if(message.attachments.size > 0){
|
||||||
|
|
@ -46,22 +44,15 @@ module.exports = {
|
||||||
}
|
}
|
||||||
// TODO: Download with correct extension.
|
// TODO: Download with correct extension.
|
||||||
message.channel.sendTyping();
|
message.channel.sendTyping();
|
||||||
let downloadResult = await this.downloadImage(url, path.resolve(directory, "input.png"));
|
if(await this.downloadImage(url, path.resolve(directory, "input.png")) != 0){
|
||||||
if(downloadResult.value != this.ERROR_CODES.SUCCESS){
|
message.channel.send("Something went wrong during the download.\nThe link might be unreachable for the bot or it's not an image.")
|
||||||
if(downloadResult.value === this.ERROR_CODES.FETCH_ERROR){
|
|
||||||
message.channel.send(`Failed to download the provided image, got error '${downloadResult.errorMessage}'`);
|
|
||||||
}else if (downloadResult.value === this.ERROR_CODES.HTTP_ERROR){
|
|
||||||
message.channel.send(`Failed to download the provided image, got response status '${downloadResult.errorMessage}'`);
|
|
||||||
}else if(downloadResult.value === this.ERROR_CODES.NOT_IMAGE){
|
|
||||||
message.channel.send(`The provided url was not an image.`)
|
|
||||||
}
|
|
||||||
fs.rmSync(`${directory}`, {recursive: true})
|
fs.rmSync(`${directory}`, {recursive: true})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const commandArgs = [tdossTemplate, "(", `${directory}/input.png`, "-resize", "800x800^", "-gravity", "center", "-extent", "1000x1000", ")", "-compose", "dst-over", "-composite", `${directory}/tdoss_result.png`]
|
const command = `magick ${dataDir}/tdoss_template.png \\( ${directory}/input.png -resize 800x800^ -gravity center -extent 1000x1000 \\) -compose dst-over -composite ${directory}/tdoss_result.png`;
|
||||||
if (executeCommand("magick", commandArgs).error === true) {
|
if (this.executeCommand(command).error === true) {
|
||||||
message.channel.send("Something went wrong during image manipulation.\nTry again and if it keeps happening, contact the owner of the bot.")
|
message.channel.send("Something went wrong during image manipulation.\nTry again and if it keeps happening, contact the owner of the bot.")
|
||||||
fs.rmSync(`${directory}`, {recursive: true})
|
fs.rmSync(`${directory}`, {recursive: true})
|
||||||
return
|
return
|
||||||
|
|
@ -75,26 +66,30 @@ module.exports = {
|
||||||
await message.channel.send({files: [final_image]})
|
await message.channel.send({files: [final_image]})
|
||||||
fs.rmSync(`${directory}`, {recursive: true})
|
fs.rmSync(`${directory}`, {recursive: true})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
executeCommand(command) {
|
||||||
|
console.log("Executing:", command)
|
||||||
|
try {
|
||||||
|
const output = execSync(command, { encoding: 'utf-8' })
|
||||||
|
if (output.length != 0)
|
||||||
|
console.log(output)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error executing ${command.split(" ")[0]} command:`, error);
|
||||||
|
return { error: true };
|
||||||
|
}
|
||||||
|
return { error: false };
|
||||||
|
},
|
||||||
// https://stackoverflow.com/a/77210219
|
// https://stackoverflow.com/a/77210219
|
||||||
async downloadImage(url, path) {
|
async downloadImage(url, path) {
|
||||||
let res;
|
const res = await fetch(url);
|
||||||
try {
|
if(!res.ok) return 1;
|
||||||
res = await fetch(url);
|
if(!res.headers.get('content-type').startsWith("image")) 2;
|
||||||
} catch (error) {
|
|
||||||
return {value: this.ERROR_CODES.FETCH_ERROR, errorMessage: error.cause?.message || error.message};
|
|
||||||
}
|
|
||||||
if(!res.ok) return {value: this.ERROR_CODES.HTTP_ERROR, errorMessage: res.status.toString()};
|
|
||||||
const contentType = res.headers.get('content-type');
|
|
||||||
if(!contentType || !contentType.startsWith("image")) return {value: this.ERROR_CODES.NOT_IMAGE, errorMessage: contentType || "No content-type header"};
|
|
||||||
const stream = Readable.fromWeb(res.body)
|
const stream = Readable.fromWeb(res.body)
|
||||||
await writeFile(path, stream);
|
await writeFile(path, stream);
|
||||||
return {value: this.ERROR_CODES.SUCCESS, errorMessage: ""};
|
return 0;
|
||||||
},
|
|
||||||
ERROR_CODES: {
|
|
||||||
SUCCESS: 0,
|
|
||||||
HTTP_ERROR: 1,
|
|
||||||
NOT_IMAGE: 2,
|
|
||||||
FETCH_ERROR: 3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ const parseTime = require('../../util/timer/parseTime');
|
||||||
const showTimer = require('../../util/timer/showTimer');
|
const showTimer = require('../../util/timer/showTimer');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "timer",
|
name: "timer",
|
||||||
description: "Set a timer for a date or time duration.",
|
description: "Set a timer for a time in minutes.",
|
||||||
moreHelp: ["Usage:"
|
moreHelp: ["Usage:"
|
||||||
,"`<prefix>timer [add|create] <time_in_minutes> <message_to_send>`"
|
,"`<prefix>timer [add|create] <time_in_minutes> <message_to_send>`"
|
||||||
,"`<prefix>timer <time>(d|h|m|s|t) <message_to_send>`"
|
,"`<prefix>timer <time>(d|h|m|s|t) <message_to_send>`"
|
||||||
,"`<prefix>timer <future_date> <message_to_send>`"
|
,"`<prefix>timer <time_in_minutes> <message_to_send>`"
|
||||||
,"`<prefix>timer edit <timer_id> <new_time_in_minutes> <new_message_to_send>` (not implemented)"
|
,"`<prefix>timer edit <timer_id> <new_time_in_minutes> <new_message_to_send>` (not implemented)"
|
||||||
,"`<prefix>timer [delete|remove] <timer_id>`"
|
,"`<prefix>timer [delete|remove] <timer_id>`"
|
||||||
,"`<prefix>timer show <timer_id>`"
|
,"`<prefix>timer show <timer_id>`"
|
||||||
|
|
@ -18,8 +18,7 @@ module.exports = {
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "add":
|
case "add":
|
||||||
case "create":
|
case "create":
|
||||||
args.shift()
|
sendText = await createTimer(message, args, false);
|
||||||
sendText = await createTimer(message, args);
|
|
||||||
break;
|
break;
|
||||||
case "edit":
|
case "edit":
|
||||||
sendText = "not implemented yet"
|
sendText = "not implemented yet"
|
||||||
|
|
@ -38,8 +37,8 @@ module.exports = {
|
||||||
sendText = "Please specify a time, and a message to send after the timer has finished";
|
sendText = "Please specify a time, and a message to send after the timer has finished";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!isNaN(parseTime(args[0], Math.floor(new Date() / 1000))) || !isNaN(Date.parse(args[0])))
|
if(!isNaN(parseTime(args[0], Math.floor(new Date() / 1000))))
|
||||||
sendText = await createTimer(message, args);
|
sendText = await createTimer(message, args, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
message.channel.send(sendText);
|
message.channel.send(sendText);
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'x',
|
|
||||||
description: 'Replaces X/Twitter links with fxtwitter and deletes the original message',
|
|
||||||
execute({message, args}) {
|
|
||||||
const noUrlErr = "You need to provide an X or twitter link to use this command."
|
|
||||||
if(args.length < 1) {
|
|
||||||
message.channel.send(noUrlErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let replacedLink = "";
|
|
||||||
const regex = /(?<=\/)(x|twitter)\.com/g
|
|
||||||
if(args[0].startsWith("https://") || args[0].startsWith("http://")){
|
|
||||||
replacedLink = args[0].replace(regex, "fxtwitter.com");
|
|
||||||
}
|
|
||||||
if(replacedLink.length === 0 || args[0] === replacedLink){
|
|
||||||
message.channel.send(noUrlErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
message.channel.send(replacedLink);
|
|
||||||
try{
|
|
||||||
message.delete()
|
|
||||||
}catch(err){
|
|
||||||
console.error(`${this.name}: An error occurred while trying to delete the original message.`)
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue