Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas leaderboard + several other tweaks #718

Merged
merged 23 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
25567a8
Leaderboard canvas update progress
Hipperooni Nov 23, 2023
aa81f42
More progress + increase username font size in profiles
Hipperooni Nov 23, 2023
75396ce
Fix for donor black colours not showing
Hipperooni Nov 23, 2023
4d089e1
Final edits before bed
Hipperooni Nov 23, 2023
2f17881
More progress
Hipperooni Nov 24, 2023
f8d0371
Make bought items automatically equip
Hipperooni Nov 24, 2023
7af5c17
Add placeholder for time option
Hipperooni Nov 24, 2023
71abe59
Many tweaks
Hipperooni Nov 26, 2023
ca73b5e
Move text resizing to canvasUtils.ts
Hipperooni Nov 26, 2023
f6216fa
99% done, almost ready for PR
Hipperooni Nov 26, 2023
2319a07
Delete deFuckify.ts - moved to canvasUtils
Hipperooni Nov 26, 2023
8b7522b
Lint
Hipperooni Nov 26, 2023
3c00e96
Squeaky clean linting
Hipperooni Nov 26, 2023
c1ca61f
3rd time lucky
Hipperooni Nov 26, 2023
ed38da4
Update tripbot's token wallet when people win or lose bets
Hipperooni Nov 26, 2023
3b37741
Update d.rpg.ts
Hipperooni Nov 26, 2023
baff495
Fix for /rpg gift showing user displayname, not guild displayname
Hipperooni Nov 27, 2023
3ee520b
Add seven new rpg fonts, remove two
Hipperooni Nov 27, 2023
63eda0c
Add vote percentages to /poll embeds
Hipperooni Nov 27, 2023
d903b3f
Fixes for /birthday and /timezone
Hipperooni Nov 28, 2023
a0698bd
Update g.birthday.ts
Hipperooni Nov 28, 2023
edf45d4
Merge branch 'canvas-leaderboard' of https://github.com/tripsit/TripB…
LunaUrsa Nov 28, 2023
f4cf77d
Separate discord out of global command
LunaUrsa Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/discord/commands/global/d.poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Message,
ChannelType,
PermissionResolvable,
MessageReaction,
} from 'discord.js';
import { stripIndents } from 'common-tags';
import { SlashCommand } from '../../@types/commandDef';
Expand Down Expand Up @@ -35,7 +36,7 @@
.setRequired(true))
.addStringOption(option => option
.setName('choices')
.setDescription('CSV of options, EG: "Red, Blue, Green"')
.setDescription('List of up to 9 options separated by commas, EG: Red, Blue, Green')
.setRequired(true)),
async execute(interaction) {
log.info(F, await commandContext(interaction));
Expand Down Expand Up @@ -77,7 +78,7 @@
await interaction.editReply('You need to provide a question and options!');
return false;
}
const optionsArray = optionsString.split(',');
const optionsArray = optionsString.split(',').map(option => option.trim());

if (optionsArray.length > 9) {
await interaction.editReply('You can only have 9 options max!');
Expand Down Expand Up @@ -149,3 +150,40 @@
};

export default dPoll;

export async function updatePollEmbed({ message, emoji: { name: emojiName } }: MessageReaction) {
log.debug(F, 'updatePollEmbed triggered');
if (emojiName && message.embeds[0] && message.embeds[0]?.footer?.text?.includes('A poll by')) {
const { description, title, footer } = message.embeds[0];
if (description) {
const totalVotes = message.reactions.cache.reduce((total, reaction) => total + reaction.count - 1, 0); // subtract one from the total votes to account for the bot's vote

Check warning on line 159 in src/discord/commands/global/d.poll.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 175. Maximum allowed is 120
const descriptionArray = description.split('\n');
const newDescriptionArray = descriptionArray.map((line, index) => {
const emoji = Object.values(emojiDict)[index];
const reaction = message.reactions.cache.get(emoji);
if (reaction) {
const percentageRegex = / - (\d+(\.\d+)?%)?$/; // matches a percentage number at the end of the line after a dash

Check warning on line 165 in src/discord/commands/global/d.poll.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 123. Maximum allowed is 120
if (totalVotes === 0) {
return line.replace(percentageRegex, ''); // remove the percentage numbers
}
const percentage = (((reaction.count - 1) / totalVotes) * 100).toFixed(0); // subtract one from the count of each reaction

Check warning on line 169 in src/discord/commands/global/d.poll.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 132. Maximum allowed is 120
if (percentageRegex.test(line)) {
return line.replace(percentageRegex, ` - ${percentage}%`); // replace the existing percentage with the new percentage

Check warning on line 171 in src/discord/commands/global/d.poll.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 129. Maximum allowed is 120
}
return `${line} - ${percentage}%`; // append the new percentage to the line
}
return line;
});
const newDescription = newDescriptionArray.join('\n');
// Create a new embed with the updated description, title and footer
const pollEmbed = embedTemplate()
.setAuthor(null)
.setTitle(title)
.setDescription(newDescription)
.setFooter({ text: footer?.text, iconURL: footer?.iconURL });
// Edit the message to use the new embed
await message.edit({ embeds: [pollEmbed] });
// log.debug(F, `Updated poll embed`);
}
}
}
6 changes: 5 additions & 1 deletion src/discord/commands/guild/d.birthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ export const dBirthday: SlashCommand = {
.setName('day'))),
async execute(interaction) {
log.info(F, await commandContext(interaction));
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
let command = interaction.options.getSubcommand() as 'get' | 'set' | undefined;
if (command === 'set') {
await interaction.deferReply({ ephemeral: true });
} else {
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
}
let member = interaction.options.getMember('user');
const monthInput = interaction.options.getString('month');
const day = interaction.options.getInteger('day');
Expand Down
Loading
Loading