Added automatic role change

master
Dany Thach 2021-10-31 01:47:15 +02:00
parent abdab986a7
commit af3a6d49d4
4 changed files with 2417 additions and 0 deletions

21
composer.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "omnicron/toadling",
"description": "Toadling bot for Discord",
"type": "project",
"license": "MIT",
"autoload": {
"psr-4": {
"Omnicron\\Toadling\\": "src/"
}
},
"authors": [
{
"name": "Dany Thach",
"email": "d.thach4@gmail.com"
}
],
"minimum-stability": "stable",
"require": {
"team-reflex/discord-php": "^6.0"
}
}

2343
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
main.php Normal file
View File

@ -0,0 +1,7 @@
<?php
require 'vendor/autoload.php';
$toadling = new \Omnicron\Toadling\Toadling;
$toadling->run();

46
src/Toadling.php Normal file
View File

@ -0,0 +1,46 @@
<?php
namespace Omnicron\Toadling;
use \Discord\Discord;
use \Discord\Parts\User\Member;
use \Discord\WebSockets\Intents;
use \Discord\WebSockets\Event;
class Toadling
{
protected Discord $discord;
public function __construct() {
$this->discord = new Discord([
'token' => 'OTAyODgxNTUzMjU5MDQ0OTM1.YXk3-Q.VYjX0smJWx4eCRVbxP_ACA3veXI',
'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS | Intents::GUILD_PRESENCES,
'loadAllMembers' => true,
]);
$this->discord->on('ready', [$this, 'initialize']);
}
public function initialize(Discord $discord) {
$discord->on(Event::GUILD_MEMBER_ADD, [$this, 'moveMemberToNotToad']);
}
public function moveMemberToNotToad(Member $member, Discord $discord) {
if('902654364685074522' !== $member->guild_id) {
return false;
}
$notToadRole = $member->guild->roles->find(function ($role) {
return '902655062982148106' === $role->id;
});
if(null === $notToadRole) {
return false;
}
$member->addRole($notToadRole);
return true;
}
public function run() {
$this->discord->run();
}
}