This commit is contained in:
Janis
2022-11-06 20:27:55 +01:00
commit aca1ef16e0
14 changed files with 4403 additions and 0 deletions

4
bot/.prettierrc Normal file
View File

@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}

25
bot/app.js Normal file
View File

@@ -0,0 +1,25 @@
const { Client, GatewayIntentBits } = require("discord.js");
const { registerCommands } = require("./commands");
const config = require("./config");
const { db, insertServer } = require("./database_handler");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
registerCommands();
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("interactionCreate", async (interaction) => {
console.log();
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === "setup") {
insertServer(interaction.guildId, interaction.guild.ownerId);
await interaction.reply("Pong!");
}
});
client.login(config.token);

27
bot/commands.js Normal file
View File

@@ -0,0 +1,27 @@
const { REST, Routes } = require("discord.js");
const config = require("./config");
const commands = [
{
name: "setup",
description: "Setup Twitch bot!",
},
];
const rest = new REST({ version: "10" }).setToken(config.token);
async function registerCommands() {
try {
console.log("Started refreshing application (/) commands.");
await rest.put(Routes.applicationCommands(config.clientId), {
body: commands,
});
console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
}
module.exports = { registerCommands };

7
bot/config.js Normal file
View File

@@ -0,0 +1,7 @@
const config = {
clientId: "1037396501732794489",
token:
"MTAzNzM5NjUwMTczMjc5NDQ4OQ.G-vEdY.yH-xVPVzErIPSLwCJ0AdNfcH-vPHX_dvNHLm3o",
};
module.exports = config;

24
bot/database_handler.js Normal file
View File

@@ -0,0 +1,24 @@
const sqlite3 = require("sqlite3").verbose();
const db = new sqlite3.Database("../database.sqlite");
function createDatabaseStructure() {
db.serialize(() => {
db.run(
"CREATE TABLE server (id INTEGER, ownerId INTEGER, twitchOAuth TEXT)"
);
});
}
function insertServer(id, ownerId, twitchOAuth) {
db.serialize(() => {
db.run(
`INSERT INTO server(id, ownerId, twitchOAuth) VALUES(${id}, ${ownerId}, '${
twitchOAuth ? twitchOAuth : "null"
}')`
);
});
}
// createDatabaseStructure();
module.exports = { db, insertServer, createDatabaseStructure };

2739
bot/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

16
bot/package.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "discord-twitch-bot",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"discord": "^0.8.2",
"discord.js": "^14.6.0",
"sqlite3": "^5.1.2"
}
}