Skip to content

Commit

Permalink
Merge pull request #350 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
Joshua branch
  • Loading branch information
JoshuaMicallefYBSU authored Oct 17, 2024
2 parents ffbf4a8 + 9b36e6a commit df74bb2
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 76 deletions.
58 changes: 57 additions & 1 deletion app/Http/Controllers/Community/DiscordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,62 @@

class DiscordController extends Controller
{

// Handel Discord Slash Commands
public function handelDiscordCommand(Request $request)
{
$data = $request->all();

return $data;

// Handle Discord's PING request
if ($data['type'] == 1) {
return response()->json(['type' => 1]);
}

// Handle the "create_issue" slash command
if ($data['type'] == 2 && $data['data']['name'] == 'report-issue') {
// Open a modal for the user to input the issue details
return response()->json([
'type' => 9, // Opens a modal
'data' => [
'custom_id' => 'create_github_issue_modal',
'title' => 'Create GitHub Issue',
'components' => [
[
'type' => 1, // Action row (holds input fields)
'components' => [
[
'type' => 4, // Input field for issue title
'custom_id' => 'issue_title',
'label' => 'Issue Title',
'style' => 1, // Short text
'placeholder' => 'Enter issue title',
'required' => true
]
]
],
[
'type' => 1, // Action row for issue description
'components' => [
[
'type' => 4, // Input field for issue description
'custom_id' => 'issue_description',
'label' => 'Issue Description',
'style' => 2, // Paragraph
'placeholder' => 'Describe the issue in detail...',
'required' => true
]
]
]
]
]
]);
}

return response()->json(['error' => 'Invalid request'], 400);
}

public function joinShortcut()
{
return redirect()->route('index', ['discord' => '1']);
Expand Down Expand Up @@ -128,7 +184,7 @@ public function linkCallbackDiscord(Request $request)
//Edit user
$user->discord_user_id = $discord_user['id'];
$user->discord_username = $discord_user['username'];
$user->member_of_czqo = true;
// $user->member_of_czqo = true;
$user->discord_avatar = $discord_user['avatar'] ? 'https://cdn.discordapp.com/avatars/'.$discord_user['id'].'/'.$discord_user['avatar'].'.png' : null;
$user->save();

Expand Down
20 changes: 18 additions & 2 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Illuminate\Http\Request;
use App\Services\DiscordClient;
use App\Jobs\ProcessMonthlyBreakdown;
use Illuminate\Support\Facades\Http;
use App\Jobs\DiscordTrainingWeeklyUpdates;

class DiscordTestController extends Controller
{
Expand All @@ -26,7 +27,7 @@ public function EditTagTest()
public function Job()
{
// Dispatch the job
$job = ProcessMonthlyBreakdown::dispatch();
$job = DiscordTrainingWeeklyUpdates::dispatch();

// Call the handle method directly to get the result synchronously
$result = $job->handle();
Expand Down Expand Up @@ -73,4 +74,19 @@ public function sendMessage()
$discord = new DiscordClient();
$discord->sendDM('200426385863344129', 'Test message');
}

public function SlashCommand()
{
$discord = new DiscordClient();

$response = $discord->getClient()->post("applications/".env('DISCORD_CLIENT_ID')."/guilds/".env('DISCORD_GUILD_ID')."/commands", [
'json' => [
'name' => 'report-issue',
'description' => 'Report a Web Issue',
'type' => 1, // 1 for slash commands
]
]);

return $response->json();
}
}
Loading

0 comments on commit df74bb2

Please sign in to comment.