mirror of
				https://github.com/DerTyp7/discord-twitch-bot.git
				synced 2025-10-30 13:17:11 +01:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										4
									
								
								bot/.prettierrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								bot/.prettierrc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| { | ||||
|   "tabWidth": 2, | ||||
|   "useTabs": false | ||||
| } | ||||
							
								
								
									
										25
									
								
								bot/app.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								bot/app.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										27
									
								
								bot/commands.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										7
									
								
								bot/config.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										24
									
								
								bot/database_handler.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										2739
									
								
								bot/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										16
									
								
								bot/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								bot/package.json
									
									
									
									
									
										Normal 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" | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Janis
					Janis