Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
Add emoji variable for channel names
Browse files Browse the repository at this point in the history
  • Loading branch information
lhvy authored and sebasptsch committed Oct 9, 2022
1 parent 142035c commit fc930b9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"discord-api-types": "^0.34.0",
"discord.js": "^14.5.0",
"dotenv": "^16.0.0",
"emoji-random-list": "^1.1.3",
"fuse.js": "^6.5.3",
"graphql": "^16.3.0",
"lodash": "^4.17.21",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Secondary" ADD COLUMN "emoji" TEXT;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ model Secondary {
id String @id @unique
name String?
creator String?
emoji String?
locked Boolean @default(false)
guildId String
guild Guild @relation(references: [id], fields: [guildId])
Expand Down
12 changes: 12 additions & 0 deletions src/classes/Secondary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
User,
VoiceBasedChannel,
} from 'discord.js';
import emojiList from 'emoji-random-list';
import { Signale } from 'signale';
import Secondaries from './Secondaries';
// eslint-disable-next-line import/no-cycle
Expand Down Expand Up @@ -76,6 +77,12 @@ export default class DynamicaSecondary {
},
});

const emoji = emojiList.random({
skintones: false,
genders: false,
group: 'smileys-and-emotion,animals-and-nature,food-and-drink',
})[0]; // random() returns an array of emojis

const secondary = await member.guild.channels.create({
type: ChannelType.GuildVoice,
name: formatChannelName(str, {
Expand All @@ -84,6 +91,7 @@ export default class DynamicaSecondary {
activities,
aliases,
memberCount: primary.members.size,
emoji,
locked: false,
}),
parent: primary.parent ?? undefined,
Expand All @@ -103,6 +111,7 @@ export default class DynamicaSecondary {
creator: member.id,
primaryId: primary.id,
guildId: guild.id,
emoji,
},
});

Expand Down Expand Up @@ -147,6 +156,8 @@ export default class DynamicaSecondary {
},
});

const { emoji } = prismaChannel;

/**
* Return aliases
*/
Expand Down Expand Up @@ -190,6 +201,7 @@ export default class DynamicaSecondary {
channelNumber: adjacentSecondaryCount + 1,
activities,
memberCount: discordChannel.members.size, // Get this
emoji,
locked,
});

Expand Down
16 changes: 14 additions & 2 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,25 @@ export default function formatChannelName(
* The number of members in the channel.
*/
memberCount: number;
/**
* Random unicode emoji.
*/
emoji: string;
/**
* If a channel is locked or not.
*/
locked: boolean;
}
) {
const { creator, channelNumber, activities, aliases, memberCount, locked } =
options;
const {
creator,
channelNumber,
activities,
aliases,
memberCount,
emoji,
locked,
} = options;

const activityList = uniq(activities);

Expand Down Expand Up @@ -95,5 +106,6 @@ export default function formatChannelName(
.replace(/@@num@@/g, memberCount.toString()) // number of channel members
.replace(/@@game@@/g, aliasedActivities.join(', ')) // Activities
.replace(/@@creator@@/g, creator) // Creator
.replace(/@@emoji@@/g, emoji) // Random unicode emoji
.replace(/<<(.+)\/(.+)>>/g, memberCount === 1 ? plurals[1] : plurals[2])}`; // Plurals
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,11 @@ duplexify@^4.1.1:
readable-stream "^3.1.1"
stream-shift "^1.0.0"

emoji-random-list@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/emoji-random-list/-/emoji-random-list-1.1.3.tgz#cf6cea95365730eded5603cfc1fd700d701c022d"
integrity sha512-KUhniFC6qVxVbTHMNQl4bvgZ3Kc6cfMoahEPzH7I7KDfshMTF98yHib0tdC4XUh+BXd2k5cpkHxGvWZ/xX5ydQ==

end-of-stream@^1.1.0, end-of-stream@^1.4.1:
version "1.4.4"
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
Expand Down

0 comments on commit fc930b9

Please sign in to comment.