Skip to content

Commit

Permalink
added banner images
Browse files Browse the repository at this point in the history
  • Loading branch information
Izocel committed May 11, 2024
1 parent 368d0bd commit ac9853e
Show file tree
Hide file tree
Showing 27 changed files with 42 additions and 15 deletions.
Binary file removed assets/img/banners/CrystalPatternsPinkBlueFastHD.jpg
Binary file not shown.
Binary file removed assets/img/banners/Hero-Banner.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes
Binary file added assets/img/banners/custom-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/banners/custom-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/banners/custom-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added assets/img/banners/dark-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/banners/dark-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
File renamed without changes
Binary file not shown.
Binary file added assets/img/banners/light-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/banners/light-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/banners/light-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/banners/light-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "A discord bot for welcoming cards",
"author": "RVÐ",
"license": "ISC",
"assets": "",
"assets": "./assets",
"scripts": {
"uglify": "node ./gulp/main.js",
"watch": "npm run build && tsc -w",
Expand Down
10 changes: 6 additions & 4 deletions src/commands/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export default new Command({
const channel = args.getChannel('channel', false, [ChannelType.GuildText])
?? guild.systemChannel;

channel.sendTyping();
interaction.channel.sendTyping();
await sendBanner(member, type, channel);
interaction.reply({ content: "Done!", ephemeral: true });
} catch (error) {
Expand All @@ -46,7 +48,7 @@ export default new Command({
export async function sendBanner(
member: GuildMember | PartialGuildMember,
type: any,
channelOveride?: any,
channelOverride?: any,
args?: any,
interaction?: any) {

Expand All @@ -62,17 +64,17 @@ export async function sendBanner(
if (!guildConfigs || !data) {
throw "No configs found...";
}

const cardData = data.card ?? defConfigs[type].card;
const getContent = data.getContent ?? defConfigs[type].getContent;

let channel = data.channelId
? member.guild.channels.cache.get((data.channelId))
: member.guild.systemChannel;
channel = channelOveride ? channelOveride : channel;
channel = channelOverride ? channelOverride : channel;

const card = await newCard.render(member, cardData.getTitle(), cardData.getMsg({ member }));
return DiscordManager.guildSend(channel, {
return await DiscordManager.guildSend(channel, {
content: getContent({ member }),
files: [card.getAttachment()]
});
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/cardHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export class CardHelper {
* Prepare a 'card' discord attachment
* @param member
* @param cardData per-user data if any
* @returns
* @returns
*/
public async render(member: GuildMember | PartialGuildMember, textTitle: string, textMessage: string) {
if (!member || member.user.bot) return;

const card = new Canvas.Welcome();
theme.setRndWelcomeStyle(card);

card.textTitle = textTitle;
card.textMessage = textMessage;
card.setUsername(member.displayName)
Expand All @@ -24,7 +26,6 @@ export class CardHelper {
.setMemberCount(member.guild.memberCount)
.setDiscriminator(member.guild.memberCount);

theme.setRndWelcomeStyle(card);
const image = await card.toAttachment();
this.attachment = new AttachmentBuilder(image.toBuffer()).attachment;
return this;
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export function toSafeJsonString(object: any) {
}

export function getRndInteger(min: number, max: number): number {
if (min === max) {
return max;
}

return Math.floor(Math.random() * (max - min)) + min;
}

Expand Down
36 changes: 28 additions & 8 deletions src/helpers/themeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,30 @@ import { getRndInteger } from "./helpers";

export class ThemeHelper {

BackgroundImages = {
WelcomerLightStyle: [
"assets/img/banners/light.jpg",
"assets/img/banners/light-1.jpg",
"assets/img/banners/light-2.jpg",
"assets/img/banners/light-4.jpg",
"assets/img/banners/light-4.jpg",
],
WelcomerDarkStyle: [
"assets/img/banners/dark.jpg",
"assets/img/banners/dark-1.jpg",
"assets/img/banners/dark-2.jpg",
],
WelcomerCustomStyle: [
"assets/img/banners/custom.jpg",
"assets/img/banners/custom-1.jpg",
"assets/img/banners/custom-2.jpg",
"assets/img/banners/custom-4.jpg",
"assets/img/banners/custom-4.jpg",
],
}

WelcomerLightStyle = {
name: "WelcomerLightStyle",
titleColor: "#ffffff",
titleBorderColor: "#000000",
usernameColor: "#000000",
Expand All @@ -19,10 +42,10 @@ export class ThemeHelper {
opacityBorder: "0.2",
opacityusernameBox: "0.5",
opacityDiscriminatorBox: "0.5",
backgroundImages: ["assets/img/banners/light.jpg"]
}

WelcomerDarkStyle = {
name: "WelcomerDarkStyle",
titleColor: "#000000",
titleBorderColor: "#ffffff",
usernameColor: "#ffffff",
Expand All @@ -39,10 +62,10 @@ export class ThemeHelper {
opacityBorder: "0.2",
opacityusernameBox: "0.5",
opacityDiscriminatorBox: "0.5",
backgroundImages: ["assets/img/banners/dark.jpg"]
}

WelcomerCustomStyle = {
name: "WelcomerCustomStyle",
titleColor: "#ffffff",
titleBorderColor: "#000000",
usernameColor: "#000000",
Expand All @@ -59,7 +82,6 @@ export class ThemeHelper {
opacityBorder: "0.2",
opacityusernameBox: "0.5",
opacityDiscriminatorBox: "0.5",
backgroundImages: ["assets/img/banners/custom.jpg"]
}

welcomerStyles = [
Expand All @@ -69,9 +91,7 @@ export class ThemeHelper {
];

setRndWelcomeStyle(card) {
const max = this.welcomerStyles.length - 1;
const rnd = Math.floor(Math.random() * (max + 1));

const rnd = getRndInteger(0, this.welcomerStyles.length - 1)
this.setWelcomeStyle(card, this.welcomerStyles[rnd]);
}

Expand Down Expand Up @@ -102,7 +122,7 @@ export class ThemeHelper {
style.opacityDiscriminatorBox ? card.setOpacity("discriminator-box", style.opacityDiscriminatorBox) : null;

// Background-Img -> will be static and png formatted
const rndIndex = getRndInteger(0, style.backgroundImages.length);
style.backgroundImages ? card.setBackground(rndIndex) : null;
const rndIndex = getRndInteger(0, this.BackgroundImages[style.name].length - 1);
card.setBackground(this.BackgroundImages[style.name][rndIndex]);
}
}

0 comments on commit ac9853e

Please sign in to comment.