-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
167 lines (136 loc) · 6.58 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const Discord = require('discord.js')
const Client = new Discord.Client({ intents: "32767" })
const { Token, apiKey } = require('./config.json')
const { Configuration, OpenAIApi } = require('openai')
Client.on('ready', async () => {
console.log(`${Client.user.tag} is now online.`)
})
const configuration = new Configuration({
apiKey: apiKey
})
const openai = new OpenAIApi(configuration)
Client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
if (interaction.commandName === 'help') {
const row = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId('rephrase')
.setEmoji("<:icons_list:1084845813856997446>")
.setLabel("Paraphrasing")
.setStyle(Discord.ButtonStyle.Success)
)
.addComponents(
new Discord.ButtonBuilder()
.setEmoji("<:icons_share:1084145568818933771>")
.setLabel('Invite Bot')
.setURL('https://discord.com/api/')
.setStyle(Discord.ButtonStyle.Link)
)
.addComponents(
new Discord.ButtonBuilder()
.setEmoji("<:icons_link:1084145529384087622>")
.setLabel('Support Server')
.setURL('https://discord.gg/')
.setStyle(Discord.ButtonStyle.Link)
)
const row2 = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setEmoji("<:icons_share:1084145568818933771>")
.setLabel('Invite Bot')
.setURL('https://discord.com/api/')
.setStyle(Discord.ButtonStyle.Link)
)
.addComponents(
new Discord.ButtonBuilder()
.setEmoji("<:icons_link:1084145529384087622>")
.setLabel('Support Server')
.setURL('https://discord.gg/')
.setStyle(Discord.ButtonStyle.Link)
)
const embed = new Discord.EmbedBuilder()
.setAuthor({ name: 'SmartWriter', iconURL: `${Client.user.avatarURL()}` })
.setDescription(`**SmartWriter** elevates your writing by providing text enhancing services powered by AI that take it to the next level.`)
.addFields(
{ name: `<:icons_members:1084728901890216016> Currently Serving`, value: `<:text:1084731926889386076> **${Client.guilds.cache.size}** servers`, inline: true },
{ name: `<:icons_ping:1084733835440304150> Websocket ping`, value: `<:text:1084731926889386076> **${Client.ws.ping}**ms`, inline: true },
)
.setColor('#FDFD96')
.setImage('https://cdn.discordapp.com/attachments/377361676514754572/1084512339514114098/Untitled3.jpg')
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.avatarURL()}` })
.setTimestamp()
const embed2 = new Discord.EmbedBuilder()
.setAuthor({ name: 'SmartWriter', iconURL: `${Client.user.avatarURL()}` })
.setDescription(`\`\`\`/rephrase :: Scans text for grammar and syntax error.\n/synonym :: Finds synonymous words.\n/antonym :: Finds antonymous words.\`\`\``)
.setColor('#FDFD96')
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.avatarURL()}` })
.setTimestamp()
await interaction.reply({ embeds: [embed], components: [row] })
const filter = i => i.customId === 'rephrase'
const filter2 = i2 => i2.customId === 'back'
const collector = interaction.channel.createMessageComponentCollector({ filter, filter2});
collector.on('collect', async i => {
await i.update({ embeds: [embed2], components: [row2]});
});
}
if (interaction.commandName === 'ping') {
await interaction.reply(`${Client.ws.ping}ms`)
}
if (interaction.commandName === 'rephrase') {
const writing = interaction.options.getString('rephrase')
await interaction.deferReply()
try {
const res = await openai.createCompletion({
model: 'text-davinci-003',
max_tokens: 2048,
temperature: 0.5,
prompt: `Rephrase "${writing}"`,
})
const embed = new Discord.EmbedBuilder()
.setColor('#FDFD96')
.setDescription(`\`\`\`${res.data.choices[0].text}\`\`\``)
await interaction.editReply({ embeds: [embed] })
} catch (e) {
console.log(e)
}
}
if (interaction.commandName === 'synonym') {
const writing = interaction.options.getString('synonym')
await interaction.deferReply()
try {
const res = await openai.createCompletion({
model: 'text-davinci-003',
max_tokens: 2048,
temperature: 0.5,
prompt: `Synonyms of "${writing}"`,
})
const embed = new Discord.EmbedBuilder()
.setColor('#FDFD96')
.setDescription(`\`\`\`${res.data.choices[0].text}\`\`\``)
await interaction.editReply({ embeds: [embed] })
} catch (e) {
console.log(e)
}
}
if (interaction.commandName === 'antonym') {
const writing = interaction.options.getString('antonym')
await interaction.deferReply()
try {
const res = await openai.createCompletion({
model: 'text-davinci-003',
max_tokens: 2048,
temperature: 0.5,
prompt: `Antonyms of "${writing}"`,
})
const embed = new Discord.EmbedBuilder()
.setColor('#FDFD96')
.setDescription(`\`\`\`${res.data.choices[0].text}\`\`\``)
await interaction.editReply({ embeds: [embed] })
} catch (e) {
console.log(e)
}
}
}
})
Client.login(Token)