Skip to content

Commit

Permalink
Fix DiscordWeeklyUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMicallefYBSU committed Oct 17, 2024
1 parent 544cb1f commit 9b36e6a
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 87 deletions.
56 changes: 56 additions & 0 deletions 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
25 changes: 11 additions & 14 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace App\Http\Controllers;

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

class DiscordTestController extends Controller
{
Expand All @@ -28,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 @@ -78,18 +77,16 @@ public function sendMessage()

public function SlashCommand()
{
$url = 'https://discord.com/api/v10/applications/1118430230839840768/guilds/' . env('DISCORD_GUILD_ID') . '/commands';
// For global commands use '/commands' without guild ID.

$commandData = [
'name' => 'hello',
'description' => 'Replies with Hello!',
'type' => 1, // 1 is for chat input commands (slash commands)
];

$response = Http::withToken(env('DISCORD_BOT_TOKEN'))
->post($url, $commandData);
$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 9b36e6a

Please sign in to comment.