Skip to content

Commit

Permalink
Merge pull request #6 from chasyumen/beta
Browse files Browse the repository at this point in the history
2.4.0 release
  • Loading branch information
chasyumen authored Sep 7, 2022
2 parents dc7f34a + eb6a741 commit c3a2cf2
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 605 deletions.
50 changes: 43 additions & 7 deletions bot/commands/verification.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Discord = require("discord.js");
const { ButtonStyle } = Discord;

module.exports = {
name: "verification",
Expand All @@ -8,6 +9,7 @@ module.exports = {
isGlobalAdminOnly: false,
slashOptions: {
options: [
{name: "view", description: "設定を確認します", type: 1, options: []},
{ name: "on", description: "メンバー認証を有効化します", type: 1, options: [] },
{ name: "off", description: "メンバー認証を無効化します", type: 1, options: [] },
{ name: "resend", description: "メンバー認証用のメッセージを再度送信します。", type: 1, options: [] },
Expand All @@ -17,15 +19,49 @@ module.exports = {
},
exec: async function (interaction, i, res) {
await res.defer();
if (!interaction.guild.me.permissions.has("MANAGE_ROLES")) {
if (!(await interaction.guild.members.fetchMe()).permissions.has(BigInt(1 << 28))) {
return await res.reply(`Botにロール管理権限がないため設定できませんでした。`);
}
var serverData = await i.guild.getdb();
if (interaction.options.getSubcommand() == "on") {
if (interaction.options.getSubcommand() == "view") {
var fieldArray = new Array({
"name": "機能を利用する (有効/無効)",
"value": serverData.verification.isEnabled ? "有効" : "無効",
"inline": true
});
// if (serverData.verification.isEnabled == true) {
fieldArray.push({
"name": "チャンネル",
"value": serverData.verification.channel !== null ?
`<#${serverData.verification.channel}> \n(ID: \`${serverData.verification.channel}\`)` :
"未登録",
"inline": true
});
fieldArray.push({
"name": "ロール",
"value": serverData.verification.role !== null ?
`<@&${serverData.verification.role}> \n(ID: \`${serverData.verification.role}\`)` :
"未登録",
"inline": true
});
fieldArray.push({
"name": "認証メッセージ",
"value": serverData.verification.latestVerifyMessage !== null ?
`https://discord.com/channels/${interaction.guild.id}/${serverData.verification.channel}/${serverData.verification.latestVerifyMessage}` :
"未登録",
"inline": true
});
// }
return await res.reply({embeds:[{
title: "メンバー認証機能設定",
color: config.default_color,
fields: fieldArray
}]});
} else if (interaction.options.getSubcommand() == "on") {
if ((serverData).verification.channel && (serverData).verification.role) {
if (interaction.guild.channels.cache.has((serverData).verification.channel)) {
var channel = interaction.guild.channels.cache.get((serverData).verification.channel);
if (!channel.permissionsFor(interaction.guild.me).has(["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"])) {
if (!channel.permissionsFor(interaction.guild.me).has([BigInt(1 << 10), BigInt(1 << 11), BigInt(1 << 14)])) {
return await res.reply(`このBotに指定されたチャンネルを見る権限、メッセージを送る権限、埋め込みリンクを送信する権限のいずれかまたはすべてが付与されていないため有効化できません。`);
}
} else {
Expand Down Expand Up @@ -71,7 +107,7 @@ module.exports = {
} else if (interaction.options.getSubcommand() == "set_channel") {
var ch = interaction.options.getChannel("channel");
if (ch.type == "GUILD_TEXT") {
if (!ch.permissionsFor(interaction.guild.me).has(["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"])) {
if (!ch.permissionsFor(interaction.guild.me).has([BigInt(1 << 10), BigInt(1 << 11), BigInt(1 << 14)])) {
return await res.reply(`このBotには指定されたチャンネルを見る権限、メッセージを送る権限、埋め込みリンクの権限のいずれかまたはすべてがありません。`);
}
if (serverData.verification.latestVerifyMessage && interaction.guild.channels.cache.has(serverData["verification"]["channel"])) {
Expand All @@ -95,7 +131,7 @@ module.exports = {
}
} else if (interaction.options.getSubcommand() == "set_role") {
var role = interaction.options.getRole("role");
var highestRole = interaction.guild.me.roles.highest;
var highestRole = (await interaction.guild.members.fetchMe()).roles.highest;
if (role.managed) {
return await res.reply(`このロールは外部サービスに管理されている(個別のBot専用のロールなど)ため付与できません。`);
}
Expand Down Expand Up @@ -131,8 +167,8 @@ module.exports = {
}

function generateMessageForVerification() {
var Button = new Discord.MessageActionRow().addComponents(
new Discord.MessageButton().setCustomId('verifyMember').setLabel('認証').setStyle('PRIMARY')
var Button = new Discord.ActionRowBuilder().addComponents(
new Discord.ButtonBuilder().setCustomId('verifyMember').setLabel('認証').setStyle(ButtonStyle.Primary)
);
return {
embeds: [{
Expand Down
29 changes: 28 additions & 1 deletion bot/commands/welcome_member.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
isGlobalAdminOnly: false,
slashOptions: {
options: [
{name: "view", description: "設定を確認します", type: 1, options: []},
{name: "on", description: "メンバー参加通知を有効化します", type: 1, options: []},
{name: "off", description: "メンバー参加通知を無効化します", type: 1, options: []},
{name: "set_channel", description: "チャンネルをセットします。", type: 1, options: [ { "name": "channel", "description": "チャンネル", "type": 7, "required": true }]},
Expand All @@ -15,7 +16,33 @@ module.exports = {
exec: async function (interaction, i, res) {
await res.defer();
console.log(await i.guild.getdb());
if (interaction.options.getSubcommand() == "on") {
if (interaction.options.getSubcommand() == "view") {
let conf_data = await i.guild.getdb();
var fieldArray = new Array({
"name": "機能を利用する (有効/無効)",
"value": conf_data.memberJoinNotify ? "有効" : "無効",
"inline": true
});
// if (conf_data.memberJoinNotify == true) {
fieldArray.push({
"name": "チャンネル",
"value": conf_data.memberJoinNotifyChannel !== null ?
`<#${conf_data.memberJoinNotifyChannel}> \n(ID: \`${conf_data.memberJoinNotifyChannel}\`)` :
"未登録",
"inline": true
});
fieldArray.push({
"name": "タイプ",
"value": `${conf_data.memberJoinNotifyType == "text" ? "テキスト" : conf_data.memberJoinNotifyType == "embed" ? "埋め込み" : null}`,
"inline": true
});
// }
return await res.reply({embeds:[{
title: "メンバー参加通知設定",
color: config.default_color,
fields: fieldArray
}]});
} else if (interaction.options.getSubcommand() == "on") {
await i.guild.setdb({memberJoinNotify: true});
return await res.reply("メンバー参加通知を有効にしました!");
} else if (interaction.options.getSubcommand() == "off") {
Expand Down
4 changes: 2 additions & 2 deletions bot/events/guildMemberAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
var serverData = await member.guild.getdb();
console.log(serverData);
if (!serverData.memberJoinNotify) {
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`false\``;
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`DISABLED\``;

client.emit("addLogQueue", "MEMBER", "JOIN", new Date(), logString);
return;
Expand All @@ -23,7 +23,7 @@ module.exports = {
client.emit("addLogQueue", "MEMBER", "JOIN", new Date(), logString);
return;
}
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`true\``;
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`ENABLED\``;

client.emit("addLogQueue", "MEMBER", "JOIN", new Date(), logString);

Expand Down
4 changes: 2 additions & 2 deletions bot/events/guildMemberRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
var serverData = await member.guild.getdb();
console.log(serverData);
if (!serverData.memberJoinNotify) {
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`false\``;
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`DISABLED\``;

client.emit("addLogQueue", "MEMBER", "LEAVE", new Date(), logString);
return;
Expand All @@ -23,7 +23,7 @@ module.exports = {
client.emit("addLogQueue", "MEMBER", "LEAVE", new Date(), logString);
return;
}
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`true\``;
var logString = `GUILD: \`${member.guild.name} (ID:${member.guild.id})\`, MEMBER: \`${member.user.tag} (ID:${member.user.id})\`, NOTIFY: \`ENABLED\``;

client.emit("addLogQueue", "MEMBER", "LEAVE", new Date(), logString);

Expand Down
8 changes: 5 additions & 3 deletions bot/events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const { InteractionType } = require("discord.js");

module.exports = {
name: "interactionCreate",
event: "interactionCreate",
exec: async function (interaction) {
if (!interaction.inGuild()) {
return await interaction.reply("このBotは現在DMでのコマンドには応答できません。");
}
if (interaction.isCommand()) {
if (interaction.type === InteractionType.ApplicationCommand) {
if (interaction.channel.isThread()) {
return false;
}
Expand Down Expand Up @@ -37,7 +39,7 @@ module.exports = {
client.emit("addLogQueue", "COMMAND", "EXECUTE", new Date(), logString);

if (client.commands.has(interaction.commandName)) {
if (client.commands.get(interaction.commandName).isServerAdminOnly && !interaction.member.permissions.has("MANAGE_GUILD")) {
if (client.commands.get(interaction.commandName).isServerAdminOnly && !interaction.member.permissions.has(BigInt(1 << 5))) {
return interaction.reply({content: "権限がありません。", ephemeral: true});
}

Expand All @@ -49,7 +51,7 @@ module.exports = {
} else {
return interaction.reply("コマンドが見つかりませんでした。");
}
} else {
} else { //interaction.type === InteractionType.MessageComponent
var res = {
reply: async function (reply) {
if (interaction.deferred) {
Expand Down
2 changes: 1 addition & 1 deletion bot/events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
}
var channelData = await message.channel.getdb();
if (channelData.autoReply) {
if (!message.channel.permissionsFor(message.guild.me).has(["VIEW_CHANNEL", "SEND_MESSAGES"])) return;
if (!message.channel.permissionsFor(message.guild.me).has([1 << 10, 1 << 11])) return;
if (message.content.match(//)) {
message.reply("いらっさい");
} else if (message.content.match(//)) {
Expand Down
12 changes: 6 additions & 6 deletions bot/events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ module.exports = {
setInterval(setPresence, 10000);
async function setPresence() {
var presences = [
{ name: `${client.guilds.cache.size} サーバー`, type: 'COMPETING' },
{ name: `新メンバー`, type: 'WATCHING' },
{ name: `バージョン ${require("../../package.json").version}`, type: 'PLAYING' },
{ name: `/help で、ヘルプを表示`, type: 'PLAYING' },
// { name: `#ゆっくり茶番劇を守れ`, type: 'WATCHING' },
{ name: `${client.guilds.cache.size} サーバー`, type: 5 },
{ name: `新メンバー`, type: 3 },
{ name: `バージョン ${require("../../package.json").version}`, type: 0 },
{ name: `/help で、ヘルプを表示`, type: 0 },
]
if (number >= (presences.length - 1)) {
number = 0;
} else {
number++;
}
client.user.setPresence({
// console.log(presences[number])
client.user.presence.set({
activities: [presences[number]],
status: "online"
});
Expand Down
36 changes: 18 additions & 18 deletions bot/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require("discord.js");
const { Client, Intents, Collection } = Discord;
const { Client, GatewayIntentBits, Collection } = Discord;
const { join } = require("path");
const { readdirSync } = require("fs");
const mongoose = (global.mongoose = require("mongoose"));
Expand All @@ -13,21 +13,21 @@ const client = (global.client = new Client({
// },
// },
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
// Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
// Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_INVITES,
// Intents.FLAGS.GUILD_VOICE_STATES,
// Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
// Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
// Intents.FLAGS.DIRECT_MESSAGE_TYPING,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
// GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
// GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildInvites,
// GatewayIntentBits.GuildVoiceStates,
// GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
// GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
// GatewayIntentBits.DirectMessageTyping,
],
allowedMentions: { repliedUser: false },
presence: {
Expand Down Expand Up @@ -101,7 +101,7 @@ setTimeout(() => {
client.login(process.env.DISCORD_TOKEN);
}, 3000);

Discord.Channel.prototype.getdb = async function () {
Discord.BaseChannel.prototype.getdb = async function () {
// console.log(client.db);
try {
var channelData = this.client.db.cache.channel.find(data => data.channelId == this.id);
Expand All @@ -121,7 +121,7 @@ Discord.Channel.prototype.getdb = async function () {
return channelData;
};

Discord.Channel.prototype.setdb = async function (data) {
Discord.BaseChannel.prototype.setdb = async function (data) {
var channelData = await this.client.db.channel.findOne({
channelId: this.id
});
Expand Down
2 changes: 1 addition & 1 deletion bot/interactions/verifyMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
}

var role = interaction.guild.roles.cache.get(serverData.verification.role);
var highestRole = interaction.guild.me.roles.highest;
var highestRole = (await interaction.guild.members.fetchMe()).roles.highest;

if (interaction.member.roles.cache.has(role.id)) {
return await res.reply({content: `あなたは既に認証済みです。`, ephemeral: true});
Expand Down
8 changes: 4 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"794119190793420810"
],
"colors": {
"default_color": "0x33FF49",
"error_color": "0xFF0000"
"default_color": 3407689,
"error_color": 16711680
},
"credits": "Made by chasyumen",
"default_color": "0x33FF49",
"logs": "994619401447931945"
"default_color": 3407689,
"logs": "1017129398698246164"
}
Loading

0 comments on commit c3a2cf2

Please sign in to comment.