Skip to content
Open
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"tangzx.emmylua"
]
}
10 changes: 3 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"Lua.diagnostics.globals": [
"Client",
"Discordia",
"Module",
"discordia"
],
"Lua.runtime.version": "LuaJIT"
"Lua.diagnostics.globals": ["Client", "Discordia", "Module", "discordia"],
"Lua.runtime.version": "LuaJIT",
"editor.formatOnSave": true,
}
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# Not a Bot

Source code of the bot of the french programming discord server NaN (Not a Name). https://discord.gg/zcWp9sC

## Requirements

- [Luvit](https://luvit.io/) runtime

## Configuration

The bot reads its config from `config.lua`, which is git-ignored (don't commit your token).

1. Copy the default config:

```bash
cp config.lua.default config.lua
```

2. Edit `config.lua` and set at minimum:
- `Token` — your Discord bot token, from the [Discord Developer Portal](https://discord.com/developers/applications) (Bot tab > Reset/Copy Token).
- `OwnerUserId` — your Discord user ID (enable Developer Mode in Discord, right-click your name, "Copy ID").

For development, create a separate test bot application on the Discord Developer Portal and invite it to a private test server. Use this bot's token in your local `config.lua` file to ensure that no code runs on the production bot or server.

### Gateway intents

The bot requires all gateway intents except for `guildIntegrations` (see `bot.lua`). Two of these are privileged and must be enabled manually on the Developer Portal (under the "Bot" tab) for your application, or the bot won't work:

- **Server Members Intent** (`guildMembers`)
- **Presence Intent** (`guildPresences`)

`AutoloadModules` lists which `module_*.lua` files load at startup — trim it while developing to only the module(s) you're working on, to reduce noise and side effects.

## Running the bot

```bash
luvit bot.lua
```
21 changes: 19 additions & 2 deletions bot.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- Copyright (C) 2018 Jérôme Leclercq
-- This file is part of the "Not a Bot" application
-- For conditions of distribution and use, see copyright notice in LICENSE

local discordia = require('discordia')
local enums = discordia.enums
local wrap = coroutine.wrap
Expand Down Expand Up @@ -270,6 +269,23 @@ Bot.ConfigTypeParser = {
end
}

Bot.ConfigTypeToCommandOptionType = {
[Bot.ConfigType.Boolean] = enums.commandOptionType.boolean,
[Bot.ConfigType.Category] = enums.commandOptionType.channel,
[Bot.ConfigType.Channel] = enums.commandOptionType.channel,
[Bot.ConfigType.Custom] = enums.commandOptionType.string,
[Bot.ConfigType.Duration] = enums.commandOptionType.string,
[Bot.ConfigType.Emoji] = enums.commandOptionType.string,
[Bot.ConfigType.Guild] = enums.commandOptionType.string,
[Bot.ConfigType.Integer] = enums.commandOptionType.integer,
[Bot.ConfigType.Member] = enums.commandOptionType.user,
[Bot.ConfigType.Message] = enums.commandOptionType.string,
[Bot.ConfigType.Number] = enums.commandOptionType.number,
[Bot.ConfigType.Role] = enums.commandOptionType.role,
[Bot.ConfigType.String] = enums.commandOptionType.string,
[Bot.ConfigType.User] = enums.commandOptionType.user,
}

client:onSync("ready", function ()
print("Logged in as " .. client.user.username)
end)
Expand All @@ -290,7 +306,8 @@ function Bot:Save()
local stopwatch = discordia.Stopwatch()

for _, moduleTable in pairs(self.Modules) do
self:ProtectedCall(string.format("Module (%s) persistent data save", moduleTable.Name), moduleTable.SavePersistentData, moduleTable)
self:ProtectedCall(string.format("Module (%s) persistent data save", moduleTable.Name),
moduleTable.SavePersistentData, moduleTable)
end

client:info("Modules data saved (%.3fs)", stopwatch.milliseconds / 1000)
Expand Down
Loading