mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-12 21:05:29 +01:00
Allow member who invited Muse to do initial setup (#561)
This commit is contained in:
parent
e1589c3013
commit
20eaed4a16
|
@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Changed
|
||||
- Muse will now allow the member who invited Muse to set config options. For this to work, the View Audit Logs permission must be given when inviting Muse. If it isn't given, Muse still works and will contact the owner instead for initial setup.
|
||||
|
||||
## [1.4.1] - 2022-03-12
|
||||
### Changed
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "Setting" ADD COLUMN "invitedByUserId" TEXT;
|
|
@ -25,6 +25,7 @@ model KeyValueCache {
|
|||
|
||||
model Setting {
|
||||
guildId String @id
|
||||
invitedByUserId String?
|
||||
playlistLimit Int @default(50)
|
||||
secondsToWaitAfterQueueEmpties Int @default(30)
|
||||
leaveIfNoListeners Boolean @default(true)
|
||||
|
|
|
@ -152,7 +152,7 @@ export default class {
|
|||
spinner.text = '📡 updating permissions...';
|
||||
await Promise.all(this.client.guilds.cache.map(async guild => updatePermissionsForGuild(guild)));
|
||||
|
||||
spinner.succeed(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=bot%20applications.commands&permissions=36700160`);
|
||||
spinner.succeed(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=bot%20applications.commands&permissions=36700288`);
|
||||
});
|
||||
|
||||
this.client.on('error', console.error);
|
||||
|
|
|
@ -6,16 +6,30 @@ import Config from '../services/config.js';
|
|||
import {prisma} from '../utils/db.js';
|
||||
import {REST} from '@discordjs/rest';
|
||||
import {Routes} from 'discord-api-types/v9';
|
||||
import updatePermissionsForGuild from '../utils/update-permissions-for-guild.js';
|
||||
|
||||
export default async (guild: Guild): Promise<void> => {
|
||||
let invitedBy;
|
||||
try {
|
||||
const logs = await guild.fetchAuditLogs({type: 'BOT_ADD'});
|
||||
invitedBy = logs.entries.find(entry => entry.target?.id === guild.client.user?.id)?.executor;
|
||||
} catch {}
|
||||
|
||||
if (!invitedBy) {
|
||||
console.warn(`Could not find user who invited Muse to ${guild.name} from the audit logs.`);
|
||||
}
|
||||
|
||||
await prisma.setting.upsert({
|
||||
where: {
|
||||
guildId: guild.id,
|
||||
},
|
||||
create: {
|
||||
guildId: guild.id,
|
||||
invitedByUserId: invitedBy?.id,
|
||||
},
|
||||
update: {
|
||||
invitedByUserId: invitedBy?.id,
|
||||
},
|
||||
update: {},
|
||||
});
|
||||
|
||||
const config = container.get<Config>(TYPES.Config);
|
||||
|
@ -33,7 +47,12 @@ export default async (guild: Guild): Promise<void> => {
|
|||
);
|
||||
}
|
||||
|
||||
const owner = await guild.fetchOwner();
|
||||
await updatePermissionsForGuild(guild);
|
||||
|
||||
await owner.send('👋 Hi! Someone (probably you) just invited me to a server you own. I can\'t be used by your server members until you complete setup by running /config set-role in your server.');
|
||||
if (invitedBy) {
|
||||
await invitedBy.send('👋 Hi! You just invited me to a server. I can\'t be used by your server members until you complete setup by running /config set-role in your server.');
|
||||
} else {
|
||||
const owner = await guild.fetchOwner();
|
||||
await owner.send('👋 Hi! Someone (probably you) just invited me to a server you own. I can\'t be used by your server members until you complete setup by running /config set-role in your server.');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,6 +26,15 @@ const updatePermissionsForGuild = async (guild: Guild) => {
|
|||
permission: false,
|
||||
},
|
||||
];
|
||||
|
||||
if (settings.invitedByUserId) {
|
||||
permissions.push({
|
||||
id: settings.invitedByUserId,
|
||||
type: 'USER',
|
||||
permission: true,
|
||||
});
|
||||
}
|
||||
|
||||
const commands = await guild.commands.fetch();
|
||||
|
||||
await guild.commands.permissions.set({fullPermissions: commands.map(command => ({
|
||||
|
|
Loading…
Reference in a new issue