Skip to content

Instantly share code, notes, and snippets.

@ZakharYA
Created January 31, 2021 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZakharYA/3ff6df2ba6dd14b11f643444f51aac8d to your computer and use it in GitHub Desktop.
Save ZakharYA/3ff6df2ba6dd14b11f643444f51aac8d to your computer and use it in GitHub Desktop.
Example for working with my library to send commits via discord bot to chats.
/**
* npm modules
*/
const FacepunchCommits = require('facepunch-commits');
const { Client } = require('discord.js');
const commits = new FacepunchCommits();
const client = new Client();
const TOKEN = 'you discord bot token';
const CHAT_ALL_ID = '754369898024534016';
const CHAT_SBOX_ID = '760145201653088266';
const CHAT_RUST_ID = '760145269702000661';
const sendInChat = async(chatId, commit) => {
const channel = await client.channels.cache.find((x) => x.id == chatId);
const repNameMinimized = commit.repo.replace(/\s/g, '');
const userNameMinimized = commit.user.name.replace(/\s/g, '');
const embed = new MessageEmbed()
.setTimestamp()
.setColor(1740997)
.setTitle(`Commit#${commit.changeset}`)
.setURL(`https://commits.facepunch.com/${commit.id}`)
.setAuthor(commit.user.name, commit.user.avatar, `https://commits.facepunch.com/${userNameMinimized}`)
.addField('Message', '```' + (commit.isHide() ? 'Hide commit' : commit.message) + '```')
.addField('Repository', `${commit.repo}/${commit.branch}`)
.setFooter(`https://commits.facepunch.com/r/${repNameMinimized}/${commit.branch}`);
await channel.send(embed);
}
commits.subscribeToAll((commit) => {
sendInChat(CHAT_ALL_ID, commit);
});
commits.subscribeToRepository('sbox', (commit) => {
sendInChat(CHAT_SBOX_ID, commit);
})
commits.subscribeToRepository('rust_reboot', (commit) => {
sendInChat(CHAT_RUST_ID, commit);
})
client.login(TOKEN);
@ZakharYA
Copy link
Author

Template bot: discord.gg/ABmYenF
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment