-
-
Notifications
You must be signed in to change notification settings - Fork 23
Create roles #75
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
Create roles #75
Conversation
|
@allcontributors please add @kamiloox for code |
|
@mmiszy I've put up a pull request to add @kamiloox! 🎉 |
src/roles/roles.ts
Outdated
| const removeMembersRoles = async (role: Role) => { | ||
| const membersWithRole = role?.members; | ||
|
|
||
| if (membersWithRole) await Promise.all(membersWithRole.map((member) => removeRole(member, role))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (membersWithRole) await Promise.all(membersWithRole.map((member) => removeRole(member, role))); | |
| if (membersWithRole) { | |
| return Promise.all(membersWithRole.map((member) => removeRole(member, role))); | |
| } |
src/roles/roles.ts
Outdated
| type Role = Discord.Role | undefined; | ||
|
|
||
| const createKarmaRole = async (guild: Guild) => { | ||
| await guild?.roles.create({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| await guild?.roles.create({ | |
| return guild.roles.create({ |
src/roles/roles.ts
Outdated
|
|
||
| type Role = Discord.Role | undefined; | ||
|
|
||
| const createKarmaRole = async (guild: Guild) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const createKarmaRole = async (guild: Guild) => { | |
| const createKarmaRole = (guild: Discord.Guild) => { |
src/roles/roles.ts
Outdated
| }; | ||
|
|
||
| const fetchKarmaRole = async (guild: Guild) => { | ||
| return guild && (await guild?.roles.fetch()).cache.find((role) => role.name === ROLE_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Czemu wszędzie guild ma typ | undefined? Nie podoba mi się to
src/roles/roles.ts
Outdated
| if (!role) await createKarmaRole(guild); | ||
| else return role; | ||
| return await fetchKarmaRole(guild); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ten return await fetchKarmaRole nigdy się nie wykona, no nie? :P
src/roles/roles.ts
Outdated
| if (!member) console.error(`Member with id ${memberId} doesn't exists!`); | ||
| if (!role) console.error(`Role for karma doesn't exists`); | ||
| else await member?.roles.add(role); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ta linijka się wykona nawet jeśli nie ma role, tak ma być?
src/roles/roles.ts
Outdated
| if (!member) console.error(`Member with id ${memberId} doesn't exists!`); | ||
| if (!role) console.error(`Role for karma doesn't exists`); | ||
| else await member?.roles.add(role); | ||
| } catch (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pozbyłbym się tego try catch stąd
src/roles/roles.ts
Outdated
| const startDate = offsetDateByWeeks(new Date(), 2); | ||
| const bestKarmaMembers = await getBestMembers(startDate); | ||
|
|
||
| await Promise.all(bestKarmaMembers.map(({ _id }) => giveRole(guild, role, _id))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| await Promise.all(bestKarmaMembers.map(({ _id }) => giveRole(guild, role, _id))); | |
| return Promise.all(bestKarmaMembers.map(({ _id }) => giveRole(guild, role, _id))); |
src/roles/roles.ts
Outdated
| const reassignRoles = async () => { | ||
| const client = new Discord.Client(); | ||
| await client.login(getConfig('DISCORD_BOT_TOKEN')); | ||
| const guild = client.guilds.cache.get(TYPE_OF_WEB_GUILD_ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A jeśli nie ma gildii w cache?
src/roles/roles.ts
Outdated
| const karmaRole = await getKarmaRole(guild); | ||
|
|
||
| await removeMembersRoles(karmaRole); | ||
| await assignMembersRoles(guild, karmaRole); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pozbyłbym się wszystkich try…catch z pozostałych funkcji i dał try…catch tylko tutaj na obie te funkcje :)
src/roles/roles.ts
Outdated
| }; | ||
|
|
||
| const fetchKarmaRole = async (guild: Discord.Guild) => { | ||
| return (await guild.roles.fetch()).cache.find((role) => role.name === ROLE_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return (await guild.roles.fetch()).cache.find((role) => role.name === ROLE_NAME); | |
| const roles = await guild.roles.fetch(); | |
| return roles.cache.find((role) => role.name === ROLE_NAME); |
src/roles/roles.ts
Outdated
| if (role) return role; | ||
| else return createKarmaRole(guild); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (role) return role; | |
| else return createKarmaRole(guild); | |
| if (role) { | |
| return role; | |
| } else { | |
| return createKarmaRole(guild); | |
| } |
src/roles/roles.ts
Outdated
| await client.login(getConfig('DISCORD_BOT_TOKEN')); | ||
| const guild = client.guilds.cache.get(TYPE_OF_WEB_GUILD_ID); | ||
|
|
||
| if (!guild) return console.error(`Guild with id ${TYPE_OF_WEB_GUILD_ID} doesn't exists!`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (!guild) return console.error(`Guild with id ${TYPE_OF_WEB_GUILD_ID} doesn't exists!`); | |
| if (!guild) { | |
| return console.error(`Guild with id ${TYPE_OF_WEB_GUILD_ID} doesn't exists!`); | |
| } |
src/roles/roles.ts
Outdated
|
|
||
| const karmaRole = await getKarmaRole(guild); | ||
|
|
||
| if (!karmaRole) return console.error(`Karma role doesn't exists!`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (!karmaRole) return console.error(`Karma role doesn't exists!`); | |
| if (!karmaRole) { | |
| return console.error(`Karma role doesn't exists!`); | |
| } |
This function gives roles for top members of the last two weeks.