namespace App\Console\Commands;
+use App\DiscordAppCommands\AlttpCommand;
+use App\Models\DiscordBotCommand as CommandModel;
use App\Models\DiscordChannel;
use App\Models\DiscordGuild;
use App\Models\DiscordRole;
use Discord\Parts\Channel\Message;
use Discord\Parts\Guild\Guild;
use Discord\Parts\Guild\Role;
+use Discord\Parts\User\Activity;
use Discord\WebSockets\Event;
+use Discord\WebSockets\Intents;
use Illuminate\Console\Command;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$logger = new Logger('DiscordBot');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
$discord = new Discord([
+ 'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS,
'logger' => $logger,
'token' => config('discord.token'),
]);
+ $discord->on('ready', function (Discord $discord) {
+ $activity = new Activity($discord);
+ $activity->type = Activity::TYPE_LISTENING;
+ $activity->name = 'HolySmoke';
+ $activity->url = 'https://alttp.localhorst.tv/';
+ $discord->updatePresence($activity);
+
+ $discord->getLoop()->addPeriodicTimer(1, function () use ($discord) {
+ $command = CommandModel::where('status', '=', 'pending')->oldest()->first();
+ if ($command) {
+ try {
+ $command->execute($discord);
+ } catch (\Exception $e) {
+ }
+ }
+ });
+
+ if (config('discord.enable_commands')) {
+ AlttpCommand::listen($discord);
+ }
+ if (config('discord.create_commands')) {
+ AlttpCommand::create($discord);
+ }
+ });
$discord->on(Event::GUILD_CREATE, function (Guild $guild, Discord $discord) {
try {
DiscordGuild::onUpstreamCreate($guild);
});
$discord->on(Event::CHANNEL_CREATE, function (Channel $channel, Discord $discord) {
try {
- DiscordGuild::onUpstreamCreate($channel);
+ DiscordChannel::onUpstreamCreate($channel);
} catch (\Exception $e) {
$this->error('channel create: '.$e->getMessage());
}
});
$discord->on(Event::CHANNEL_UPDATE, function (Channel $channel, Discord $discord, ?Channel $old) {
try {
- DiscordGuild::onUpstreamUpdate($channel);
+ DiscordChannel::onUpstreamUpdate($channel);
} catch (\Exception $e) {
$this->error('channel update: '.$e->getMessage());
}
});
$discord->on(Event::CHANNEL_DELETE, function ($channel, Discord $discord) {
try {
- DiscordGuild::onUpstreamDelete($channel);
+ DiscordChannel::onUpstreamDelete($channel);
} catch (\Exception $e) {
$this->error('channel delete: '.$e->getMessage());
}
$this->error('guild role delete: '.$e->getMessage());
}
});
- $discord->on('ready', function (Discord $discord) {
- $discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
- if (!empty($message->guild_id)) return;
- if (!empty($message->webhook_id)) return;
- if (!empty($message->application_id)) return;
- if (is_null($message->author)) return;
- if ($message->author->bot) return;
- $discord->getLoop()->addTimer(0.6, function() use ($message) {
- $message->react('😄');
- });
- if (!is_null($message->channel)) {
- $discord->getLoop()->addTimer(2.0, function() use ($message) {
- $message->channel->sendMessage('bugger off');
- });
- } else {
- $message->delayedReply('bugger off', 2000);
- }
- });
- });
$discord->getLoop()->addSignal(SIGINT, function() use ($discord) {
$discord->close();
});