mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(discord-bot): check if the member has the role
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"discord": {
|
||||
"token": "YOUR-BOT-TOKEN-HERE",
|
||||
"id": "1038762591805247518"
|
||||
"id": "1038762591805247518",
|
||||
"trainRole": "965267139902705744"
|
||||
},
|
||||
|
||||
"telegram": {
|
||||
"token": "YOUR-BOT-TOKEN-HERE"
|
||||
"token": "YOUR-BOT-TOKEN-HERE"
|
||||
},
|
||||
|
||||
"server": {
|
||||
|
||||
@@ -5,11 +5,17 @@ import {
|
||||
SelectMenuBuilder,
|
||||
ComponentType
|
||||
} from 'discord.js';
|
||||
|
||||
export default {
|
||||
data: new ContextMenuCommandBuilder()
|
||||
.setName('Train Message')
|
||||
.setType(ApplicationCommandType.Message),
|
||||
async execute(interaction) {
|
||||
if (!interaction.member.roles.cache.get(global.config.discord.trainRole))
|
||||
return interaction.reply({
|
||||
content: 'You don\'t have the permission to do this.',
|
||||
ephemeral: true
|
||||
});
|
||||
const options = [];
|
||||
|
||||
for (const { label } of global.config.responses) {
|
||||
|
||||
@@ -4,7 +4,10 @@ export default {
|
||||
name: Events.MessageCreate,
|
||||
once: false,
|
||||
execute(msg) {
|
||||
if (!msg.content) return;
|
||||
msg.client.helper.scanText(msg.content.toLowerCase(), `${msg.channelId}/${msg.id}`);
|
||||
if (!msg.content || msg.author.bot) return;
|
||||
msg.client.helper.scanText(
|
||||
msg.content.toLowerCase(),
|
||||
`${msg.channelId}/${msg.id}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,30 +1,40 @@
|
||||
export default {
|
||||
command: /\/train/,
|
||||
async execute(msg) {
|
||||
console.log(msg);
|
||||
if (msg.reply_to_message.message_id === msg.message_thread_id) return global.bot.sendMessage(msg.chat.id, 'Please reply to a message!', {
|
||||
message_thread_id: msg.message_thread_id, reply_to_message_id: msg.message_id
|
||||
});
|
||||
command: /\/train/,
|
||||
async execute(msg) {
|
||||
console.log(msg);
|
||||
if (msg.reply_to_message.message_id === msg.message_thread_id)
|
||||
return global.bot.sendMessage(msg.chat.id, 'Please reply to a message!', {
|
||||
message_thread_id: msg.message_thread_id,
|
||||
reply_to_message_id: msg.message_id
|
||||
});
|
||||
|
||||
const options = [];
|
||||
const options = [];
|
||||
|
||||
for (const { label } of global.config.responses) {
|
||||
for (const { label } of global.config.responses) {
|
||||
options.push({
|
||||
text: label,
|
||||
callback_data: `label_${label.toLowerCase()}`
|
||||
});
|
||||
}
|
||||
|
||||
const admins = await global.bot.getChatAdministrators(msg.chat.id);
|
||||
const isAdmin = admins.find(admin => admin.user.id === msg.from.id);
|
||||
const admins = await global.bot.getChatAdministrators(msg.chat.id);
|
||||
const isAdmin = admins.find((admin) => admin.user.id === msg.from.id);
|
||||
|
||||
if (!isAdmin) return global.bot.sendMessage(msg.chat.id, 'You\'re not an admin.', {
|
||||
message_thread_id: msg.message_thread_id, reply_to_message_id: msg.message_id
|
||||
});
|
||||
global.bot.sendMessage(msg.chat.id, 'Please select the corresponding label to train the bot.', {
|
||||
message_thread_id: msg.message_thread_id, reply_to_message_id: msg.reply_to_message.message_id, reply_markup: {
|
||||
inline_keyboard: [options]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!isAdmin)
|
||||
return global.bot.sendMessage(msg.chat.id, 'You\'re not an admin.', {
|
||||
message_thread_id: msg.message_thread_id,
|
||||
reply_to_message_id: msg.message_id
|
||||
});
|
||||
global.bot.sendMessage(
|
||||
msg.chat.id,
|
||||
'Please select the corresponding label to train the bot.',
|
||||
{
|
||||
message_thread_id: msg.message_thread_id,
|
||||
reply_to_message_id: msg.reply_to_message.message_id,
|
||||
reply_markup: {
|
||||
inline_keyboard: [options]
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,10 +9,13 @@ export default {
|
||||
|
||||
if (Number(aiRes.predictions[0].score) >= response.threshold) {
|
||||
const ids = aiRes.id.split('/');
|
||||
|
||||
global.bot.sendMessage(ids[0], response.text, { message_thread_id: ids[1], reply_to_message_id: ids[2] });
|
||||
|
||||
return;
|
||||
|
||||
global.bot.sendMessage(ids[0], response.text, {
|
||||
message_thread_id: ids[1],
|
||||
reply_to_message_id: ids[2]
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
export default {
|
||||
name: 'callback_query',
|
||||
once: false,
|
||||
async execute(cb) {
|
||||
const admins = await global.bot.getChatAdministrators(cb.message.chat.id);
|
||||
const isAdmin = admins.find(admin => admin.user.id === cb.message.from.id);
|
||||
name: 'callback_query',
|
||||
once: false,
|
||||
async execute(cb) {
|
||||
const admins = await global.bot.getChatAdministrators(cb.message.chat.id);
|
||||
const isAdmin = admins.find(
|
||||
(admin) => admin.user.id === cb.message.from.id
|
||||
);
|
||||
|
||||
if (!isAdmin) return global.bot.sendMessage(cb.message.chat.id, 'You\'re not an admin.', {
|
||||
message_thread_id: cb.message.message_thread_id, reply_to_message_id: cb.message.message_id
|
||||
});;
|
||||
if (!isAdmin)
|
||||
return global.bot.sendMessage(
|
||||
cb.message.chat.id,
|
||||
'You\'re not an admin.',
|
||||
{
|
||||
message_thread_id: cb.message.message_thread_id,
|
||||
reply_to_message_id: cb.message.message_id
|
||||
}
|
||||
);
|
||||
|
||||
global.helper.sendTrainData(cb.message.reply_to_message.text.toLowerCase(), cb.data.replace('label_', '').toUpperCase());
|
||||
global.helper.sendTrainData(
|
||||
cb.message.reply_to_message.text.toLowerCase(),
|
||||
cb.data.replace('label_', '').toUpperCase()
|
||||
);
|
||||
|
||||
global.bot.sendMessage(cb.message.chat.id, 'Sent train data to server.', {
|
||||
message_thread_id: cb.message.message_thread_id, reply_to_message_id: cb.message.message_id
|
||||
});
|
||||
}
|
||||
}
|
||||
global.bot.sendMessage(cb.message.chat.id, 'Sent train data to server.', {
|
||||
message_thread_id: cb.message.message_thread_id,
|
||||
reply_to_message_id: cb.message.message_id
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
export default {
|
||||
name: 'message',
|
||||
once: false,
|
||||
async execute(msg) {
|
||||
if (!msg.text) return;
|
||||
global.helper.scanText(msg.text.toLowerCase(), `${msg.chat.id}/${msg.message_thread_id}/${msg.message_id}`);
|
||||
}
|
||||
}
|
||||
name: 'message',
|
||||
once: false,
|
||||
async execute(msg) {
|
||||
if (!msg.text) return;
|
||||
global.helper.scanText(
|
||||
msg.text.toLowerCase(),
|
||||
`${msg.chat.id}/${msg.message_thread_id}/${msg.message_id}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ global.config = JSON.parse(configJSON);
|
||||
global.helper = new HelperClient(global.config);
|
||||
global.helper.connect();
|
||||
|
||||
global.bot = new TelegramBot(config.telegram.token, { polling: true });
|
||||
global.bot = new TelegramBot(global.config.telegram.token, { polling: true });
|
||||
|
||||
const commandsPath = join(__dirname, 'commands');
|
||||
const commandFiles = readdirSync(commandsPath).filter((file) =>
|
||||
@@ -31,7 +31,7 @@ for (const file of commandFiles) {
|
||||
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const tgEventsPath = join(__dirname, 'events/telegram');
|
||||
const tgEventFiles = readdirSync(tgEventsPath).filter((file) =>
|
||||
@@ -63,4 +63,4 @@ for (const file of helperEventFiles) {
|
||||
} else {
|
||||
global.helper.on(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user