Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
Fixed all the API bugs found in testing. Now fully working.
  • Loading branch information
Rayth committed Jun 21, 2021
1 parent c9287bb commit 44a24c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 6 additions & 5 deletions PrismaBot/Modules/Admin/Prisma.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Discord.Commands;
using Discord;
using System;
using System.Threading.Tasks;
using PrismaBot.PrismaAPI;

Expand All @@ -10,10 +11,10 @@ public class Prisma : ModuleBase
[Command("console")]
[Remarks("Sends a command to your Prisma Console")]
[RequireUserPermission(GuildPermission.Administrator)]
public async Task Console([Remainder] string command)
public async Task ConsoleCmd([Remainder] string command)
{
PrisAPI Prisma = new PrisAPI();
Prisma.Console(command);
await Prisma.ConsoleCmdAsync(command);
await ReplyAsync("Command Executed.");
}

Expand All @@ -23,7 +24,7 @@ public async Task Console([Remainder] string command)
public async Task Start()
{
PrisAPI Prisma = new PrisAPI();
Prisma.StartServer();
await Prisma.StartServerAsync();
await ReplyAsync("Server Started.");
}

Expand All @@ -33,7 +34,7 @@ public async Task Start()
public async Task Stop()
{
PrisAPI Prisma = new PrisAPI();
Prisma.StopServer();
await Prisma .StopServerAsync();
await ReplyAsync("Server Stopped.");
}

Expand All @@ -43,7 +44,7 @@ public async Task Stop()
public async Task Restart()
{
PrisAPI Prisma = new PrisAPI();
Prisma.RestartServer();
await Prisma .RestartServerAsync();
await ReplyAsync("Server restarted.");
}
}
Expand Down
15 changes: 10 additions & 5 deletions PrismaBot/PrismaAPI/PrismaAPI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using PrismaBot.Config;
using System.Collections.Generic;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace PrismaBot.PrismaAPI
{
Expand All @@ -10,7 +11,7 @@ public class PrisAPI
private string User = BotConfig.Load().APIUser;
private string Server = BotConfig.Load().APIServer;

public void Console(string command)
public async Task ConsoleCmdAsync(string command)
{
using HttpClient httpClient = new HttpClient();

Expand All @@ -21,39 +22,43 @@ public void Console(string command)
request.Content = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("command", command),
});
HttpResponseMessage response = await httpClient.SendAsync(request);
return;
}

public void StartServer()
public async Task StartServerAsync()
{
using HttpClient httpClient = new HttpClient();

using HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("POST"), "https://prisma.cubedhost.com/api/server/" + Server + "/start");
request.Headers.TryAddWithoutValidation("Content-Type", "application/json");
request.Headers.TryAddWithoutValidation("X-Api-Key", Key);
request.Headers.TryAddWithoutValidation("X-Api-User", User);
HttpResponseMessage response = await httpClient.SendAsync(request);
return;
}

public void StopServer()
public async Task StopServerAsync()
{
using HttpClient httpClient = new HttpClient();

using HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("POST"), "https://prisma.cubedhost.com/api/server/" + Server + "/stop");
request.Headers.TryAddWithoutValidation("Content-Type", "application/json");
request.Headers.TryAddWithoutValidation("X-Api-Key", Key);
request.Headers.TryAddWithoutValidation("X-Api-User", User);
HttpResponseMessage response = await httpClient.SendAsync(request);
return;
}

public void RestartServer()
public async Task RestartServerAsync()
{
using HttpClient httpClient = new HttpClient();

using HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("POST"), "https://prisma.cubedhost.com/api/server/" + Server + "/restart");
request.Headers.TryAddWithoutValidation("Content-Type", "application/json");
request.Headers.TryAddWithoutValidation("X-Api-Key", Key);
request.Headers.TryAddWithoutValidation("X-Api-User", User);
HttpResponseMessage response = await httpClient.SendAsync(request);
return;
}

Expand Down

0 comments on commit 44a24c2

Please sign in to comment.