Best laravel framework open-source packages.

Kaiju

Kaiju is an open source verification bot based on Discord's OAuth written in C# and PHP, with the functionality of being able to integrate the user to a new server in case yours is suspended.
Updated 1 year ago

What is Kaiju?

Kaiju is an open source verification bot for Discord servers, based on OAuth and with permission for the server owner, to be able to migrate users to a new server in case the current one is suspended.

How does it work?

Kaiju uses the OAuth of discord, this serves to guarantee access of the user's account with specific permissions to the bot.

The user must enter a website (which can be modified using the instructions below specified), where by clicking the login button, he will be redirected to the discord.com page with OAuth, after logging in, he will be asked to allow the entry of the bot to its account, asking for the permissions identify and guild.join, these will be used to obtain the ID of the user's account and an access token that will allow the owner to put the user's account to a new server.

Features:

  • Use prepared statements to the database
  • Discord bot included to be able to verify users and migrate to a new server
  • Discord BOT Made on .NET Core

Requirements:

  • PHP 7.2+
  • MySQL
  • NET Core Runtime 3.1+ Downloaded (for compatibility with the Discord Bot)

Concepts

API Discord Web Login

I made a page where they use the classes to start the session and obtain the verification key (https://github.com/biitez/Kaiju/blob/master/Kaiju%20Server%20Files/index.php), But if you want to make your own page using Kaiju classes, here you can find the functions that you can use:

First, you must open a session in the first line of the page and include Kaiju.php and Include.php, like this:

session_start();

require_once 'Classes/Kaiju.php';
require_once 'Include.php';

Initialize the Kaiju class, setting what you put in Inlude.php as a parameter, like this:

$KaijuHandler = new Kaiju(Client_Id, RedirectUrl, Secret_Id);

You must connect the database to the initialized function, like this:

$KaijuHandler->ConnectDatabase(DATABASE_HOST, DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD);

To obtain the URL where the user must be redirected to log in through discord, you must call:

$DiscordUrlLogin = $KaijuHandler->GenerateUrl();

For the 'callback' after the user logs in from the previously generated page, it will be redirected to the link that you put in the OAuth of your application on the Discord page along with some query parameters, to receive it, you must write this:

$KaijuLogInResponse = $KaijuHandler->LogIn($_GET);

The login method returns a BOOL if the login was correct and a STRING if it was incorrect, you can handle it this way:

if (is_bool($KaijuLogInResponse)) {
  # Succcessfully Logged
} else {
  echo "Error: $KaijuLogInResponse";
}

If the login was correct, you can get the user's basic information (Id, Nombre, Discriminator, Avatar, Access Token)

PD: Access Token is stored from Kaiju class in database

$userInfo = $KaijuHandler->GetUserInfo();
$AccessToken = $userInfo['accessToken'];

$Username = $userInfo['Username'];
$Discriminator = $userInfo['Discrim'];
$accountId = $userInfo['Id'];
$AvatarUrl = $userInfo['AvatarUrl'];
$Locale = $userInfo['Locale'];

To obtain the verification code that the user must write in the discord command, you must call the initialization, like this:

$VerificationKey = $KaijuHandler->VerificationKey;

Steps to integrate Kaiju

  1. Create an application in the application portal of your account (https://discord.com/developers/applications)

Portal Developer

  1. Go to your application, go to the section 'OAuth', copy the Client Id and Client Secret

OAuth IDs

  1. Open the files from the server, open Include.php and paste them where they correspond.

Includes

  1. In your application portal, go to 'BOT', copy the Token and paste it in Include.php.

Bot Token

  1. Go back to the OAuth section in the application portal and paste the link where the server files will be in 'Redirects', for example, if you upload the server files to example.com inside kaiju directory, there you put https://example.com/kaiju/, you should also be able to do it in Include.php

OAuth Redirect

OAuth Redirect

  1. Inside the Include.php file, you will find a variable called APISecretKey, there place a Random string, like a password, this will be used in the requests between bot->server, you must also place it in the Settings.json file for the bot's discord.

SecretKeyBot SecretKeyPHP

  1. Import 'kaiju.sql' that you can find in this repository to your database.

Database Table

Now, download the Discord Bot that you can find in Releases, open the file 'Settings.json' and put the information of your bot that you can find in your previously created application. You must go to your discord server, create the rank for the members, copy the ID and paste it in VerifiedRankId You must place the URL of the API of this project there, as I mentioned before, if you placed the server files in https://example.com/ inside the kaiju directory, there you must place https://example.com/kaiju/api/ In the KaijuSecretKeyCommunication space, put the password placed in Include.php, as mentioned in instruction 6.

Discord Bot Settings

  1. Go to the 'OAuth' section of the application on Discord, and put the bot on your server. Also give it administrator permissions.

Bot OAuth

Add Bot

Make sure that the rank of the bot is ABOVE the rank of the members.

  1. Fill the Include.php file with your database credentials among other things

  2. To migrate the users registered in the database to a new server, you must integrate the bot to the new server, copy the ID by right-clicking on the icon and place the command: !Migrate ID, if everything goes well, the bot will respond with a command telling you about the users that were entered to the server.

(If users log into the page, there will appear the statistics of when they are migrated.)

Preview

Intructions Discord Bot

Extra: Any error will appear in the console.

Discord Bot Windows

To host the bot on Windows, make sure you have downloaded .NET Core Runtime 3.1+ (https://dotnet.microsoft.com/download/dotnet/3.1/runtime), After downloading it, just open the file Kaiju.DiscordBot.exeand your bot will start.

Discord Bot Ubuntu

To host it in Ubuntu, you will need to put commands in the CLI,

First, make sure you have the .NET Core Runtime downloaded by placing the command:

dotnet

If you receive an error, continue you must type the following commands to download it:

sudo apt update 
sudo apt install apt-transport-https -y
sudo apt install dotnet-runtime-3.1 

Now, upload the bot files (including the dll's), go to the path and you can open a process with:

nohup dotnet Kaiju.DiscordBot.dll > dotnetcore.log &

To close it, you must find the PID of the process by placing the command:

ps wx

A list of processes will open, look for the discord bot and type:

kill PID

Screenshots:

Log In AppLogIn

Extra

This project was created only by me in my free time, if you find any errors, please notify me, if you want to improve it open a pull request!

Credits: