You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GeekQu_sspanel/app/Utils/Discord.php

74 lines
2.8 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Utils;
use App\Models\User;
use App\Services\Config;
class Discord
{
public static function set()
{
$loop = \React\EventLoop\Factory::create();
$client = new \CharlotteDunois\Yasmin\Client(array(), $loop);
$client->on('error', static function ($error) {
echo $error . PHP_EOL;
});
$client->on('ready', static function () use ($client) {
echo 'Logged in as ' . $client->user->tag . ' created on ' . $client->user->createdAt->format('d.m.Y H:i:s') . PHP_EOL;
});
$client->on('message', static function ($message) {
//echo 'Received Message from '.$message->author->tag.' in '.($message->channel->type === 'text' ? 'channel #'.$message->channel->name : 'DM').' with '.$message->attachments->count().' attachment(s) and '.\count($message->embeds).' embed(s)'.PHP_EOL;
if (strpos($message->content, '!bind') === 0) {
bindQR($client, $message);
} elseif (strpos($message->content, '!checkin') === 0) {
checkin($client, $message);
} elseif (strpos($message->content, '!traffic') === 0) {
traffic($client, $message);
}
});
$client->login(Config::get('discord_token'))->done();
$loop->run();
echo('<27><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD>' . PHP_EOL);
}
public static function bindQR($client, $message)
{
$message->channel->send('<27><><EFBFBD>ڽ<EFBFBD><DABD>룬<EFBFBD><EBA3AC><EFBFBD>Ժ󡣡<D4BA><F3A1A3A1><EFBFBD>');
$attachments = $message->attachments->toArray();
reset($attachments);
$qrcode_text = QRcode::decod(current($attachments)->url);
if ($qrcode_text == null) {
$message->channel->send('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>');
return;
}
if (strpos($qrcode_text, 'mod://bind/') === 0 && strlen($qrcode_text) == 27) {
$uid = TelegramSessionManager::verify_bind_session(substr($qrcode_text, 11));
if ($uid == 0) {
$message->channel->send('<27><>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>' . substr($qrcode_text, 11) . '<27><>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Ϊ10<31><30><EFBFBD>ӣ<EFBFBD><D3A3>볢<EFBFBD><EBB3A2>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD>վ<EFBFBD>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD>ϱ༭<CFB1><E0BCAD>ҳ<EFBFBD><D2B3><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD>ά<EFBFBD><CEAC>');
return;
}
$user = User::where('id', $uid)->first();
$user->discord = $message->author->id;
$user->im_type = 5;
$user->im_value = $message->author->username;
$user->save();
$reply['message'] = '<27>󶨳ɹ<F3B6A8B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣺' . $user->email;
}
$message->channel->send('δ֪<CEB4><D6AA><EFBFBD>ݶ<EFBFBD>ά<EFBFBD><CEAC>');
}
public static function checkin($client, $message)
{
}
public static function traffic($client, $message)
{
}
}