Created
January 31, 2021 10:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Template bot: discord.gg/ABmYenF