Skip to content

Commit

Permalink
Merge pull request #7 from winglessraven/dev
Browse files Browse the repository at this point in the history
Toggle buttons to show, add new manage server button
  • Loading branch information
winglessraven authored Jan 10, 2022
2 parents a24d940 + f97fc53 commit 0df9f0b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
32 changes: 25 additions & 7 deletions DiscordBotPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,18 @@ private async Task GetServerInfo(bool updateExisting, SocketUserMessage msg)

//add buttons
var builder = new ComponentBuilder();
builder.WithButton("Start Server", "start-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Success);
builder.WithButton("Stop Server", "stop-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Danger);
builder.WithButton("Restart Server", "restart-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Danger);
builder.WithButton("Kill Server", "kill-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Danger);
builder.WithButton("Update Server", "update-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Primary);

if(_settings.MainSettings.ShowStartButton)
builder.WithButton("Start Server", "start-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Success);
if(_settings.MainSettings.ShowStopButton)
builder.WithButton("Stop Server", "stop-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Danger);
if(_settings.MainSettings.ShowRestartButton)
builder.WithButton("Restart Server", "restart-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Danger);
if(_settings.MainSettings.ShowKillButton)
builder.WithButton("Kill Server", "kill-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Danger);
if(_settings.MainSettings.ShowUpdateButton)
builder.WithButton("Update Server", "update-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Primary);
if(_settings.MainSettings.ShowManageButton)
builder.WithButton("Manage Server", "manage-server-" + aMPInstanceInfo.InstanceId, ButtonStyle.Primary);

//if updating an existing message
if (updateExisting)
Expand All @@ -446,6 +452,7 @@ private async Task GetServerInfo(bool updateExisting, SocketUserMessage msg)
await existingMsg.ModifyAsync(x =>
{
x.Embed = embed.Build();
x.Components = builder.Build();
});
}
else
Expand Down Expand Up @@ -611,7 +618,11 @@ private async Task OnButtonPress(SocketMessageComponent arg)
application.Update();
await ButtonResonse("Update", arg);
}

if (arg.Data.CustomId.Equals("manage-server-" + aMPInstanceInfo.InstanceId))
{
await ManageServer(arg);
await ButtonResonse("Manage", arg);
}
}

private async Task ButtonResonse(string Command, SocketMessageComponent arg)
Expand Down Expand Up @@ -717,6 +728,13 @@ private async void UserLeaves(object sender, UserEventArgs args)
await _client.GetGuild(guildID).GetTextChannel(eventChannel.Id).SendMessageAsync(embed: embed.Build());
}
}

private async Task ManageServer(SocketMessageComponent arg)
{
var builder = new ComponentBuilder();
builder.WithButton("Manage Server",style: ButtonStyle.Link, url: "https://" + _settings.MainSettings.ManagementURL + "/?instance=" + aMPInstanceInfo.InstanceId);
await arg.User.SendMessageAsync("Link to management panel:",components: builder.Build());
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions DiscordBotPlugin/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ public class DiscordBotSettings : SettingSectionStore
[WebSetting("Post Join and Leave Messages Channel Name", "(channel name to post player join and leave events)", false)]
public string PostPlayerEventsChannel = "";

[WebSetting("Base Management URL", "(address used to manage instances, should be in the format of amp.domain.com or your external IP if you do not use a domain)", false)]
public string ManagementURL = "";

[WebSetting("Display Start Button", "(toggle the start button visibility on the info message)", false)]
public bool ShowStartButton = false;

[WebSetting("Display Stop Button", "(toggle the stop button visibility on the info message)", false)]
public bool ShowStopButton = false;

[WebSetting("Display Restart Button", "(toggle the restart button visibility on the info message)", false)]
public bool ShowRestartButton = false;

[WebSetting("Display Kill Button", "(toggle the kill button visibility on the info message)", false)]
public bool ShowKillButton = false;

[WebSetting("Display Update Button", "(toggle the update button visibility on the info message)", false)]
public bool ShowUpdateButton = false;

[WebSetting("Display Manage Button", "(toggle the manage button visibility on the info message)", false)]
public bool ShowManageButton = false;
}

public DiscordBotSettings MainSettings = new DiscordBotSettings();
Expand Down

0 comments on commit 0df9f0b

Please sign in to comment.