Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 57ee05d

Browse files
committed
try to fix mongodb file
1 parent d7073a0 commit 57ee05d

1 file changed

Lines changed: 59 additions & 57 deletions

File tree

mongo/bot.js

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
const { Client, GatewayIntentBits, Partials, Permissions, EmbedBuilder } = require("discord.js");
12
const client = new Client({
23
intents: [
3-
Intents.FLAGS.GUILDS,
4-
Intents.FLAGS.GUILD_MEMBERS,
5-
Intents.FLAGS.GUILD_MESSAGES,
6-
Intents.FLAGS.DIRECT_MESSAGES,
7-
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
8-
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS
4+
GatewayIntentBits.Guilds,
5+
GatewayIntentBits.GuildMembers,
6+
GatewayIntentBits.GuildMessages,
7+
GatewayIntentBits.DirectMessages,
8+
GatewayIntentBits.DirectMessageReactions
99
],
10-
partials: ["CHANNEL"]
10+
partials: [Partials.Channel]
1111
}) // not sure about intents, though
1212
const { REST } = require("@discordjs/rest");
1313
const { Routes } = require("discord-api-types/v9");
14-
const config = require("../config.json"); // located at the root of the repo
14+
const config = require("../config.json");
15+
const strings = require("../strings.json");
1516
const { paste } = require("ubuntu-pastebin");
16-
const { Client, Intents, Permissions, MessageEmbed } = require("discord.js");
1717
const mongo = require("mongoose");
1818
const {User,Channel,Ticket} = require("./db.js");
1919

@@ -35,20 +35,21 @@ client.once("ready", async () => {
3535
client.login(process.env.TOKEN) // located at ../process.env
3636

3737
client.on("messageCreate", async message => {
38-
39-
// Refuse pending/timed out/bots/mentions
40-
if(message.guild.member(message.author).communicationDisabledUntilTimestamp !== null) return message.author.send("Hey!\nLooks like you're on timeout. You can't use the modmail while on timeout.")
41-
if(message.guild.member(message.author).pending) return message.author.send("Hey!\nYou still have to pass the guild's membership gate to use the modmail.")
42-
if(message.content.includes("@everyone") || message.content.includes("@here")) return message.author.send("You're not allowed to use those mentions.");
43-
if(message.author.bot) return;
38+
const author = message.author;
39+
if(author.bot) return;
40+
let guild = await client.guilds.fetch(config.id.server);
41+
if(guild.members.fetch(author.id).communicationDisabledUntilTimestamp !== null && config.permissions.disableOnTimeout === true) return message.author.send(strings.disableOnTimeout);
42+
if(guild.members.fetch(author.id).pending) return message.author.send(strings.pending);
43+
let text = message.content.replace(/[`]|@everyone|@here/g, '');
44+
// Use table from 1.1.9
45+
const table = db.table("Support13")
4446

4547
if(message.channel.type === "DM"){
4648

4749
// Get the guild from the DB and Discord then get the channel from Discord
4850
let active = await User.findOne({target: message.author.id});
49-
if(config.dmUsers === false) return message.author.send("Hey!\nSorry, but the modmail is currently closed. If you already have an open ticket, it will be kept open.");
50-
if(active.block === true) return message.author.send("You are not allowed to use the modmail.");
51-
if(active.onHold === true) return message.author.send("The support team put your ticket on hold. Please wait until they get back to you.")
51+
if(config.enabled === false) return message.author.send(strings.disabled);
52+
if(block === true) return message.author.send(strings.blocked);
5253
let guild = await client.guilds.fetch(config.guild);
5354
let tc = await guild.channels.fetch(config.ticketCategory);
5455
let channel, found = true;
@@ -65,47 +66,48 @@ client.on("messageCreate", async message => {
6566
}
6667

6768
// Create the channel
68-
channel = await guild.channels.create(`${message.author.username}`, {
69-
type: "GUILD_TEXT",
70-
topic: `#${ticket} | From ${message.author.username}`,
71-
parent: tc,
72-
reason: `${message.author.id} opened a ticket through the modmail service.`,
73-
permissionOverwrites: [
74-
{id: guild.roles.everyone, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
75-
{id: guild.roles.fetch(config.roles.mod), allow: [
76-
Permissions.FLAGS.VIEW_CHANNEL,
77-
Permissions.FLAGS.SEND_MESSAGES,
78-
Permissions.FLAGS.EMBED_LINKS,
79-
Permissions.FLAGS.READ_MESSAGE_HISTORY
80-
]},
81-
{id: guild.roles.fetch(config.roles.bot), allow: [
82-
Permissions.FLAGS.VIEW_CHANNEL,
83-
Permissions.FLAGS.SEND_MESSAGES,
84-
Permissions.FLAGS.ATTACH_FILES,
85-
Permissions.FLAGS.EMBED_LINKS,
86-
Permissions.FLAGS.READ_MESSAGE_HISTORY
87-
]}
88-
]
89-
});
69+
channel = await guild.channels.create({
70+
name: `${message.author.username}`,
71+
topic: `#${ticket} | From ${message.author.username}`,
72+
parent: ticketcategory,
73+
reason: `${message.author.id} opened a ticket through the modmail service.`,
74+
permissionOverwrites: [
75+
{id: guild.roles.everyone, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
76+
{id: guild.roles.resolve(config.roles.mod), allow: [
77+
Permissions.FLAGS.VIEW_CHANNEL,
78+
Permissions.FLAGS.SEND_MESSAGES,
79+
Permissions.FLAGS.ATTACH_FILES,
80+
Permissions.FLAGS.EMBED_LINKS,
81+
Permissions.FLAGS.READ_MESSAGE_HISTORY
82+
]},
83+
{id: guild.members.resolve(client.user.id), allow: [
84+
Permissions.FLAGS.VIEW_CHANNEL,
85+
Permissions.FLAGS.SEND_MESSAGES,
86+
Permissions.FLAGS.ATTACH_FILES,
87+
Permissions.FLAGS.EMBED_LINKS,
88+
Permissions.FLAGS.READ_MESSAGE_HISTORY
89+
]}
90+
]
91+
});
9092

9193
// Send the new ticket embed
92-
let author = message.author;
93-
const log_newTicket = new MessageEmbed()
94-
.setAuthor(author.tag, author.avatarURL())
95-
.setDescription(`opened ticket #${ticket}.`)
96-
.setTimestamp()
97-
.setColor("0x6666ff")
98-
let logs = await client.channels.fetch(config.log)
99-
logs.send({embeds: [log_newTicket]});
100-
message.author.send(`Hello! Thanks for getting in touch. Our support team will get back to you quickly.`);
101-
let supportData = new User({ticket: ticket.number, target: author.id ,channel: channel.id});
102-
await supportData.save();
103-
let channelData = new Channel({channel: channel.id, author: author.id});
104-
await channelData.save();
105-
let text = message.content;
106-
await channel.send({content: `${message.author.username} opened this ticket.`})
107-
await channel.send({content: text}); // Send plain text
108-
return;
94+
let author = message.author;
95+
const log_newTicket = new MessageEmbed()
96+
.setAuthor(author.tag, author.avatarURL())
97+
.setDescription(`opened ticket #${ticket}.`)
98+
.setTimestamp()
99+
.setColor("0x6666ff")
100+
let logs = await client.channels.fetch(config.log)
101+
logs.send({embeds: [log_newTicket]});
102+
message.author.send(`Hello! Thanks for getting in touch. Our support team will get back to you quickly.`);
103+
let supportData = new User({ticket: ticket.number, target: author.id ,channel: channel.id});
104+
await supportData.save();
105+
let channelData = new Channel({channel: channel.id, author: author.id});
106+
await channelData.save();
107+
let text = message.content;
108+
await channel.send({content: `${message.author.username} opened this ticket.`})
109+
await channel.send({content: text}); // Send plain text
110+
return;
109111

110112
};
111113
channel = guild.channels.cache.get(active.channel);

0 commit comments

Comments
 (0)