Skip to content

Commit

Permalink
add debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
timgoeller committed Jan 10, 2021
1 parent e0f956c commit 34e03b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
# Cabal-Discord Bridge
You can use this tool, to automatically send messages from Cabal to Discord and vice-versa.

You can use this tool, to automatically send messages from Cabal to Discord and vice-versa.

## Steps to Run
* Clone the repository
* Create a config (see the config section)
* Add Discord bot to server, and give it a role with 'Manage Webhooks' permission
* Run `node index`

- Clone the repository
- Create a config (see the config section)
- Add Discord bot to server, and give it a role with 'Manage Webhooks' permission
- Run `node index`

## Config

For this bridge to work, a `config.json` file must exist at the application root. You can take a look at `config.example.json` to see how this file is structured.

#### cabalKey

This is the key of the cabal that you want to bridge.

#### discordSecret

This is a token for a Discord bot. Take a look at [https://discord.com/developers/docs/intro] to see how to create a bot. The bridge will work on all severs that you add this bot to.

#### mappings

This array defines how messages should be passed between Cabal and Discord.

```js
"discord": [] // Array of Discord channels for this mapping
"cabal": [] // Array of Cabal channels for this mapping
"from": "cabal" || "discord" || "both" // Defines the direction in which messages should be bridged
```

#### logging
Set to `true`, to display forwarded messages along with meta information in console.

Set to `true` or `'info'`, to display forwarded messages along with meta information in console. Set it to `'debug'` to also display information about recieved events.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ discordBot.on('ready', async () => {
})

function processMessageFromDiscord (msg, hooks) {
log(2, `recieved msg event from discord: [author:${msg.author.username}:${msg.author.id}] [channel:#${msg.channel.name}] [msg:${msg.content}]`)
if (discordBot.user.id !== msg.author.id && !hooks.sentByBot(msg)) {
const cabalChannelsToForwardTo = new Set()
config.mappings.forEach(mapping => {
Expand All @@ -71,6 +72,7 @@ function processMessageFromDiscord (msg, hooks) {
}

function processMessageFromCabal (envelope, hooks) {
log(2, `recieved msg event from cabal: [author:${envelope.author.name}:${envelope.author.id}] [channel:#${envelope.channel}] [msg:${envelope.message.value.content.text}]`)
const discordChannelsToForwardTo = new Set()
config.mappings.forEach(mapping => {
if (mapping.from === 'cabal' || mapping.from === 'both') {
Expand Down Expand Up @@ -111,6 +113,10 @@ function log (type, message) {
case 1: // from discord
console.log(`(${getTimestampPretty()}) ` + chalk.bold.greenBright('[discord->cabal] ') + message)
break
case 2:
if (config.logging === 'debug') {
console.log(`(${getTimestampPretty()}) ` + chalk.gray(message))
}
}
}
}
Expand Down

0 comments on commit 34e03b3

Please sign in to comment.