This commit is contained in:
jrmyr 2025-04-30 13:54:14 +00:00
parent f7a9ecee86
commit 87c650174c
3 changed files with 41 additions and 39 deletions

View File

@ -271,7 +271,8 @@ async function onMessage(client, cfg, message) {
// Previous response ID for context continuity // Previous response ID for context continuity
const prev = client.pb?.cache?.get(key); const prev = client.pb?.cache?.get(key);
// Enforce minimum score to use AI responses // Enforce minimum score to use AI responses
// Enforce minimum score to use AI responses, but allow guild admins // Enforce minimum score to use AI responses if scorekeeper is enabled
if (client.scorekeeper) {
try { try {
const isAdmin = message.member?.permissions?.has(PermissionFlagsBits.Administrator); const isAdmin = message.member?.permissions?.has(PermissionFlagsBits.Administrator);
const scoreData = await client.scorekeeper.getScore(message.guild.id, message.author.id); const scoreData = await client.scorekeeper.getScore(message.guild.id, message.author.id);
@ -284,6 +285,7 @@ async function onMessage(client, cfg, message) {
} catch (err) { } catch (err) {
client.logger.error(`Error checking score: ${err.message}`); client.logger.error(`Error checking score: ${err.message}`);
} }
}
// Build request body, prefixing with a mention of who spoke // Build request body, prefixing with a mention of who spoke
const speakerMention = `<@${message.author.id}>`; const speakerMention = `<@${message.author.id}>`;
const body = { const body = {

View File

@ -169,7 +169,8 @@ export const commands = [
), ),
async execute(interaction, client) { async execute(interaction, client) {
const cfg = client.config.responses; const cfg = client.config.responses;
// Enforce minimum score to use /query, allow guild admins to bypass // Enforce minimum score to use /query if scorekeeper is enabled
if (client.scorekeeper) {
try { try {
const isAdmin = interaction.member?.permissions?.has(PermissionFlagsBits.Administrator); const isAdmin = interaction.member?.permissions?.has(PermissionFlagsBits.Administrator);
const scoreData = await client.scorekeeper.getScore(interaction.guildId, interaction.user.id); const scoreData = await client.scorekeeper.getScore(interaction.guildId, interaction.user.id);
@ -183,6 +184,7 @@ export const commands = [
client.logger.error(`Error checking score: ${err.message}`); client.logger.error(`Error checking score: ${err.message}`);
return interaction.reply({ content: 'Error verifying your score. Please try again later.', ephemeral: true }); return interaction.reply({ content: 'Error verifying your score. Please try again later.', ephemeral: true });
} }
}
const prompt = interaction.options.getString('prompt'); const prompt = interaction.options.getString('prompt');
const flag = interaction.options.getBoolean('ephemeral'); const flag = interaction.options.getBoolean('ephemeral');
const ephemeral = flag !== null ? flag : true; const ephemeral = flag !== null ? flag : true;

View File

@ -425,26 +425,23 @@ export const commands = [
const scoreData = await client.scorekeeper.getScore(interaction.guildId, targetUser.id); const scoreData = await client.scorekeeper.getScore(interaction.guildId, targetUser.id);
const multiplierValue = 1 + (scoreData.commendations * commendationValue) - (scoreData.citations * citationValue); const multiplierValue = 1 + (scoreData.commendations * commendationValue) - (scoreData.citations * citationValue);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setAuthor({ name: `${client.user.username}: Scorekeeper Module`, iconURL: client.user.displayAvatarURL() })
.setTitle(`I/O Score for ${(await interaction.guild.members.fetch(targetUser.id).catch(() => null))?.displayName || targetUser.username}`) .setTitle(`I/O Score for ${(await interaction.guild.members.fetch(targetUser.id).catch(() => null))?.displayName || targetUser.username}`)
.setColor(0x00AE86) .setColor(0x00AE86)
.setThumbnail(targetUser.displayAvatarURL()) .setThumbnail(targetUser.displayAvatarURL())
.setDescription('I/O is a mechanism to rank the users within a system based on the resources they put into the system and the resources they take from it. The resulting priority score can be used for a variety of dystopian purposes.')
.addFields( .addFields(
{ name: 'Total Score', value: `**${scoreData.totalScore.toFixed(2)}**`, inline: false },
{ name: 'Commendations', value: `**${scoreData.commendations}**`, inline: false }, { name: 'Commendations', value: `**${scoreData.commendations}**`, inline: false },
{ name: 'Citations', value: `**${scoreData.citations}**`, inline: false }, { name: 'Citations', value: `**${scoreData.citations}**`, inline: false },
{ name: 'Input Score', value: `**${scoreData.input}**`, inline: true }, { name: 'Input', value: `${scoreData.input}`, inline: true },
{ name: 'Output Score', value: `**${scoreData.output}**`, inline: true } { name: 'Output', value: `${scoreData.output}`, inline: true },
{ name: 'Priority Score', value: `${scoreData.totalScore.toFixed(2)}`, inline: true },
{ name: 'Base Output', value: `-# ${baseOutput}`, inline: true },
{ name: 'Commendation Value', value: `-# ${commendationValue}`, inline: true },
{ name: 'Citation Value', value: `-# ${citationValue}`, inline: true },
{ name: 'Multiplier Formula', value: `-# 1 + (${scoreData.commendations} * ${commendationValue}) - (${scoreData.citations} * ${citationValue}) = ${multiplierValue.toFixed(2)}`, inline: false },
{ name: 'Priority Score Formula', value: `-# ${multiplierValue.toFixed(2)} × ${scoreData.input} / (${scoreData.output} + ${baseOutput}) = ${scoreData.totalScore.toFixed(2)}`, inline: false },
) )
.addFields({
name: 'Formula',
value:
`CV = ${commendationValue}\n` +
`CiV = ${citationValue}\n` +
`BO = ${baseOutput}\n` +
`M = 1 + **${scoreData.commendations}** × CV - **${scoreData.citations}** × CiV\n` +
`M × **${scoreData.input}** / (**${scoreData.output}** + BO) = **${scoreData.totalScore.toFixed(2)}**`,
inline: false
})
.setFooter({ text: 'Last decay: ' + new Date(scoreData.lastDecay).toLocaleDateString() }) .setFooter({ text: 'Last decay: ' + new Date(scoreData.lastDecay).toLocaleDateString() })
.setTimestamp(); .setTimestamp();
@ -495,6 +492,7 @@ export const commands = [
} }
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setAuthor({ name: `${client.user.username}: Scorekeeper Module`, iconURL: client.user.displayAvatarURL() })
.setTitle('I/O Score Leaderboard') .setTitle('I/O Score Leaderboard')
.setColor(0x00AE86) .setColor(0x00AE86)
.setDescription(leaderboardText) .setDescription(leaderboardText)