-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make bot suitable for multiple servers #67
base: main
Are you sure you want to change the base?
Changes from all commits
85c8760
fd70c16
4995264
a6ec446
e234055
2d747db
71c2ce7
5a9aa1c
cbbc884
b9720d6
7715410
9c783f2
8039320
f674a3c
b07350b
30d3291
0562f9b
de52e50
ddf631b
dbafe11
98d344e
8cd3e63
b9717e1
3d57787
e1f9748
605c754
ce7ec95
63a7386
455ec2f
9e824dd
73d79e1
e792bc7
c4ff6ef
6159b6d
be2da22
467feae
122ee6c
bdbb762
a5f07af
c9384fa
087688c
7a8142a
ad8c527
9d95b3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
/node_modules/ | ||
yarn-error.log | ||
/build/ | ||
settings.json | ||
settings.json | ||
settings.db |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,16 @@ | ||||||
# Trojaner Bot | ||||||
This is a [Discord](https://discord.com) bot currently only running on my [Discord server](https://discord.gg/NdsmmwV). There is no official way of adding this bot to your own Discord server. | ||||||
This is a [Discord](https://discord.com) bot currently only running on my [Discord server](https://discord.gg/NdsmmwV). To add this bot on your server, use the following link: | ||||||
|
||||||
## Adding the bot to your server | ||||||
1. Click the following link: https://discord.com/api/oauth2/authorize?client_id=632637013475983360&permissions=8&scope=bot%20applications.commands | ||||||
- Note that the bot is added with admin privileges. You may alter the permissions value but keep in mind that some features might not work or lead to unexpected behavior | ||||||
2. (Optional, can be done later) Set up the following text-channels | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- `#live` for a nice embed showing people selected by you who are currently live on Twitch | ||||||
- `#roles` for a customizable role management | ||||||
3. (Optional, can be done later) Set up the bot using the following admin commands: | ||||||
- `/permit <add|remove> <role>` adds/removes `<role>` as permitted. Every user with that role can execute privileged commands. | ||||||
- `/stream-channel <option|list> …` adds Twitch streamers to show in a `#live` channel. If a channel called `#live` does not exist, this does not work | ||||||
- `/roles <add|remove> <role> …` adds/removes roles for the role manager (channel `#roles` is required) | ||||||
|
||||||
## Deployment and contribution | ||||||
### Requirements | ||||||
Comment on lines
15
to
16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add docker deployment explanation |
||||||
|
@@ -24,16 +35,13 @@ Where you replace… | |||||
- `<TWITCH_TOKEN> (optional)` with your client secret generated after you create an application in the [Twitch Developer Console](https://dev.twitch.tv/console/apps) which is only required if you want to use the Twitch features of this bot | ||||||
- `<OAUTH_TOKEN>` with the OAuth token you get from your application's OAuth page (`https://discord.com/developers/applications/{YOUR_APP_ID}/oauth2/general` → Client Secret) | ||||||
|
||||||
Execute the bot as described in [Execution](https://github.com/TrojanerHD/TrojanerBot/#Execution). It will generate a `settings.json` file in the bot directory and will already work. You can, however, modify the content of `settings.json` (you need to restart the bot if you added a Twitch ID or roles): | ||||||
Execute the bot as described in [Execution](https://github.com/TrojanerHD/TrojanerBot/#Execution). It will generate a `settings.json` file in the bot directory and will already work. You can, however, modify the content of `settings.json` (you need to restart the bot if you added a Twitch ID): | ||||||
#### Settings | ||||||
In this step I will go over all properties of the `settings.json` file: | ||||||
|
||||||
Key | Type | Description | Default | ||||||
--- | --- | --- | --- | ||||||
`twitch-id` | string | The ID of your Twitch application found in the [Twitch Developer Console](https://dev.twitch.tv/console/apps). If you do not want to use the Twitch features of this bot, set the value to `""` | `""` | ||||||
`permission-roles` | string[] | Added roles will be able to execute commands that require permissions (e. g. /bye) | `[]` | ||||||
`roles` | {name: string; emoji: string; description?: string}[] | Added roles will be displayed in a `#roles` channel in Discord if the Discord has this channel. The emoji id will be used as reaction emoji so when a user reacts with the certain emoji they will get the role respectively. If you do not want to use this feature, set the value to `[]` | `[]` | ||||||
`streamers` | string[] | The bot will show whenever the here specified channels are live in a `#live` channel in Discord if the Discord has this channel. If you do not want to use this feature, set the value to `[]` | `[]` | ||||||
`streamer-subscriptions` | {streamer: string; subscribers: string[]} | The bot will store all subscriptions to Twitch streamers when somebody uses `/streamer` to subscribe to a streamer. Usually you want to leave it as it is | `[]` | ||||||
`logging` | "errors" \| "warnings" \| "verbose" | The log-level. "warnings" will inform if, for example, twitch id was set but a token was not provided | `"warnings"` | ||||||
`express-port` | number \| undefined | The port the express app will listen on | `undefined` | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { Guild } from 'discord.js'; | ||
import DiscordClient from './DiscordClient'; | ||
import Settings from './Settings'; | ||
import GuildSettings from './settings/GuildSettings'; | ||
import { GuildInfo } from './settings/SettingsDB'; | ||
|
||
/** | ||
* Checks what features are enabled in the settings | ||
|
@@ -14,22 +18,17 @@ export default class FeatureChecker { | |
*/ | ||
#crash: boolean = false; | ||
|
||
constructor() { | ||
public async check() { | ||
if (Settings.settings.logging === 'verbose') | ||
this.status('Logging set to verbose'); | ||
if (Settings.settings['permission-roles'].length === 0) | ||
this.warning('No permitted roles set (field "permission-roles" empty)'); | ||
if (Settings.settings.roles.length === 0) this.status('Roles disabled'); | ||
else this.status('Roles enabled'); | ||
for (const guild of DiscordClient._client.guilds.cache.toJSON()) | ||
await this.checkGuild(guild); | ||
|
||
if (Settings.settings['twitch-id']) | ||
if (process.env.TWITCH_TOKEN) this.status('Twitch enabled'); | ||
else this.warning('No Twitch token provided'); | ||
else if (process.env.TWITCH_TOKEN) this.warning('No Twitch ID provided'); | ||
else this.status('Twitch disabled'); | ||
if (Settings.settings.roles.length > 25) | ||
this.error( | ||
'Currently, only a maximum of 25 roles is allowed. If you need more, file an issue at https://github.com/TrojanerHD/TrojanerBot/issues/new' | ||
); | ||
if ( | ||
process.argv[ | ||
process.argv.findIndex((value: string): boolean => value === '-r') + 1 | ||
|
@@ -42,6 +41,42 @@ export default class FeatureChecker { | |
if (this.#crash) process.exit(1); | ||
} | ||
|
||
public async checkGuild(guild: Guild): Promise<void> { | ||
const guildInfo: string = `for guild ${guild.id} (${guild.name})`; | ||
let error: boolean = false; | ||
try { | ||
const info: GuildInfo = await GuildSettings.settings(guild.id); | ||
if (info.permissionRoles.length === 0) | ||
this.status(`No permitted roles set for ${guildInfo}`); | ||
if (info.roles.length === 0) this.status(`Roles disabled ${guildInfo}`); | ||
else this.status(`Roles enabled ${guildInfo}`); | ||
if (info.roles.length > 25) { | ||
error = true; | ||
this.error( | ||
`Currently, only a maximum of 25 roles is allowed. Guild ${guild.id} (${guild.name}) has more than 25 roles. If you need more, file an issue at https://github.com/TrojanerHD/TrojanerBot/issues/new`, | ||
false | ||
); | ||
} | ||
} catch (e: unknown) { | ||
error = true; | ||
this.error( | ||
`Could not load information ${guildInfo} with reason ${e}`, | ||
false | ||
); | ||
} finally { | ||
if (!error) { | ||
DiscordClient._safeGuilds.push(guild); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check if safe guilds doesn't already have this guild to make this function safe when re-executing |
||
if (!GuildSettings.settings(guild.id)) | ||
await GuildSettings.saveSettings(guild, { | ||
permissionRoles: [], | ||
roles: [], | ||
streamers: [], | ||
refreshToken: '', | ||
}).catch(console.error); | ||
} else this.warning(`Limited features due to problems ${guildInfo}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove a guild from the safe guilds if there was a problem to make this function safe when re-executing |
||
} | ||
} | ||
|
||
/** | ||
* Appends a warning to the log output | ||
* @param message The warning message to append | ||
|
@@ -63,9 +98,10 @@ export default class FeatureChecker { | |
/** | ||
* Appends an error to the log output and will crash the bot | ||
* @param message The error message to append | ||
* @param crash Whether to crash the bot | ||
*/ | ||
private error(message: string): void { | ||
private error(message: string, crash: boolean = true): void { | ||
this.#message += `Error: ${message}\n`; | ||
this.#crash = true; | ||
if (!this.#crash) this.#crash = crash; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.