This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
108 lines (100 loc) · 4.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { Client, GatewayIntentBits, ActivityType, EmbedBuilder, AttachmentBuilder, StringSelectMenuBuilder, ActionRowBuilder } from 'discord.js';
import { deploy } from './deploy_commands.js';
import { config } from 'dotenv';
import { Handle } from './HandleLink.js';
import { HandleTranslate } from './HandleTranslate.js';
import { openSettings } from './slashHandler.js';
import { setMode } from './dbManager.js';
import { Translate } from '@google-cloud/translate/build/src/v2';
config();
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent,] });
const translate = new Translate({ projectId: process.env.PROJECT_ID, key: process.env.GOOGLE_KEY });
client.on ('ready', () => {
deploy(client.user.id);
console.log (`Ready on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users`);
client.user.setActivity('x.com | twitter.com', { type: ActivityType.Watching });
});
client.on('messageCreate', async (message) => {
if (message.content.startsWith('https://twitter.com/') || message.content.startsWith('https://x.com/')) {
await Handle(message);
}
if (message.mentions.has(client.user) && message.content == (`<@${client.user.id}>`)) {
const embed = new EmbedBuilder()
.setColor('#1DA1F2')
.setTitle('XFixer')
.addFields(
{ name: 'What is this?', value: 'XFixer is a bot that enhances Twitter/X embeds in Discord.' },
{ name: 'How does it work?', value: 'Just send a link to a Twitter/X post, and I will automatically reply with more information about the post.' },
{ name: 'How can I add this bot?', value: 'Visit https://mikn.link/xfixer/' },
{ name: 'Disclaimer', value: 'This bot is not affiliated with Twitter/X Corp.' }
)
.setFooter({ text: 'XFixer by MikanDev' });
message.reply({ embeds: [embed] });
}
if (message.mentions.has(client.user) && message.content.includes(`<@${client.user.id}> steal`)) {
try{
const emoji = message.content.split(' ')[2];
console.log(emoji);
const emojiID = emoji.split(':')[2].replace('>', '');
const emojiname = emoji.split(':')[1];
const emojiURL = `https://cdn.discordapp.com/emojis/${emojiID}.png?size=128`;
const response = await fetch(emojiURL);
const attachment = new AttachmentBuilder(response.body, 'emoji.png');
const roles = message.guild.roles.cache.filter(role => role.managed === false);
await message.guild.emojis.create(attachment, emojiname, roles);
message.reply({ content: `Successfully added ${emojiname} to this server!` });
}
catch (error) {
message.reply({ content: 'Error adding emoji. Make sure you mention the emoji correctly.' });
console.log(error);
}
}
if (message.mentions.has(client.user) && message.content.includes(`<@${client.user.id}> asteal`)) {
try{
const emoji = message.content.split(' ')[2];
console.log(emoji);
const emojiID = emoji.split(':')[2].replace('>', '');
const emojiname = emoji.split(':')[1];
console.log(emojiname);
const emojiURL = `https://cdn.discordapp.com/emojis/${emojiID}.gif?size=128`;
const response = await fetch(emojiURL);
const attachment = new AttachmentBuilder(response.body, 'emoji.gif');
const roles = message.guild.roles.cache.filter(role => role.managed === false);
await message.guild.emojis.create(attachment, emojiname, roles);
message.reply({ content: `Successfully added ${emojiname} to this server!` });
}
catch (error) {
message.reply({ content: 'Error adding emoji. Make sure you mention the emoji correctly.' });
console.log(error);
}
}});
client.on('interactionCreate', async (interaction) => {
if (interaction.customId === 'delete') {
await interaction.message.delete();
}
if (interaction.commandName === 'settings') {
}
if (interaction.customId.startsWith('mode')) {
const invoker = interaction.customId.split('-')[2];
const mode = interaction.customId.split('-')[1];
if (invoker === interaction.user.id) {
if (mode === 'disable') {
await setMode(interaction.guildId, 'disable');
await interaction.reply({ content: 'Disabled XFixer for this server.', ephemeral: true });
}
if (mode === 'video') {
await setMode(interaction.guildId, 'video');
await interaction.reply({ content: 'Set XFixer to Video Only mode for this server.', ephemeral: true });
}
if (mode === 'full') {
await setMode(interaction.guildId, 'full');
await interaction.reply({ content: 'Set XFixer to Full Tweet mode for this server.', ephemeral: true });
}
}
}
if (interaction.customId === 'translate') {
await HandleTranslate(interaction);
}
}
);
client.login(process.env.DISCORD_TOKEN);