Skip to content

Commit

Permalink
Bing Chat joins the debugging fun
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsunami014 committed Dec 6, 2023
1 parent 4d1d909 commit 66d7d48
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions .github/scripts/notifyDiscord.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { Client, Intents, Events } = require('discord.js');

const { token } = process.env.DISCORD_TOKEN;

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent] });
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

function processMessage(message, user) {
if (message.includes(`@${user}`)) {
if (message.mentions.users.has(user.id)) {
return 'very';
} else {
return `hard.\n@${user} is working`;
return `hard.\n@${user.tag} is working`;
}
}

let previousMessage = null;
client.once(Events.Ready, async () => {
console.log(`Ready! Logged in as ${client.user.tag}`);

client.once(Events.ClientReady, async (readyClient) => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);

const channel = readyClient.channels.cache.get('1181875066280091688'); // Replace with your channel ID
const channel = client.channels.cache.get('1181875066280091688'); // Replace with your channel ID

if (channel) {
console.log(`We got a channel :)`);

try {
const messages = await channel.messages.fetch({ limit: 20 }); // Fetch up to 10 previous messages
const messages = await channel.messages.fetch({ limit: 10 }); // Fetch up to 10 previous messages

// Iterate through the fetched messages
for (const [, message] of messages) {
if (message.content.includes('@')) {
// Check if the message contains an '@' mention
messages.forEach(message => {
if (message.mentions.users.size > 0) {
// Check if the message contains any user mentions
const githubActor = process.env.GITHUB_ACTOR;
console.log(`GitHub actor: ${githubActor}`);
const newMsg = processMessage(message.content, githubActor);
console.log(`Message: ${newMsg}`);
channel.send(newMsg)
.then(() => {
console.log(`Sent message: ${newMsg}`);
process.exit(); // Exit the process after sending the message
})
.catch(error => {
console.error(`Error sending message: ${error}`);
process.exit(); // Exit the process after sending the message
});
// Find the first mentioned user whose username matches the github actor
const mentionedUser = message.mentions.users.find(user => user.username === githubActor);
if (mentionedUser) {
// If a matching user is found, process the message
const newMsg = processMessage(message, mentionedUser);
console.log(`Message: ${newMsg}`);
channel.send(newMsg)
.then(() => {
console.log(`Sent message: ${newMsg}`);
process.exit(); // Exit the process after sending the message
})
.catch(error => {
console.error(`Error sending message: ${error}`);
process.exit(); // Exit the process after sending the message
});
}
}
}
});

// If no message with an '@' mention is found
console.log('No message with an "@" mention found.');
// If no message with a user mention is found
console.log('No message with a user mention found.');
process.exit(); // Exit the process

} catch (error) {
Expand Down

0 comments on commit 66d7d48

Please sign in to comment.