Skip to content

Commit

Permalink
Merge pull request #98 from winglessraven/dev
Browse files Browse the repository at this point in the history
TABS
  • Loading branch information
winglessraven authored May 29, 2024
2 parents 0e9a4f0 + 857805b commit 8d8305b
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 86 deletions.
60 changes: 29 additions & 31 deletions DiscordBotPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using ModuleShared;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Discord;
using Discord.Commands;
using System.Linq;
using Discord.Net;
using System.Text.RegularExpressions;
using Discord.WebSocket;
using LocalFileBackupPlugin;
using ModuleShared;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Newtonsoft.Json;
using LocalFileBackupPlugin;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace DiscordBotPlugin
{
Expand Down Expand Up @@ -47,7 +47,7 @@ public PluginMain(ILogger log, IConfigSerializer config, IPlatformInfo platform,
aMPInstanceInfo = AMPInstanceInfo;
features = Features;

features.PostLoadPlugin(application,"LocalFileBackupPlugin");
features.PostLoadPlugin(application, "LocalFileBackupPlugin");
features.RegisterFeature(BackupProvider);
backupProvider = BackupProvider;

Expand Down Expand Up @@ -219,8 +219,6 @@ public async Task ConnectDiscordAsync(string BotToken)
if (_settings.MainSettings.DiscordDebugMode)
config.LogLevel = LogSeverity.Debug;

//config.GatewayHost = "wss://gateway.discord.gg";

// Initialize Discord client with the specified configuration
_client = new DiscordSocketClient(config);

Expand Down Expand Up @@ -638,13 +636,13 @@ private async Task UpdateWebPanel(string webPanelPath)
// Write content to the files
ResourceReader reader = new ResourceReader();

if(!File.Exists(scriptFilePath))
if (!File.Exists(scriptFilePath))
File.WriteAllText(scriptFilePath, reader.ReadResource("script.js"));

if(!File.Exists(stylesFilePath))
if (!File.Exists(stylesFilePath))
File.WriteAllText(stylesFilePath, reader.ReadResource("styles.css"));

if(!File.Exists(panelFilePath))
if (!File.Exists(panelFilePath))
File.WriteAllText(panelFilePath, reader.ReadResource("panel.html"));

//variables
Expand Down Expand Up @@ -702,7 +700,7 @@ private async Task UpdateWebPanel(string webPanelPath)
}
else
{
uptime = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", 0,0,0,0);
uptime = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", 0, 0, 0, 0);
}
if (onlinePlayerCount > 0 && _settings.MainSettings.ShowOnlinePlayers)
{
Expand All @@ -725,7 +723,7 @@ private async Task UpdateWebPanel(string webPanelPath)
if (_settings.MainSettings.ShowPlaytimeLeaderboard)
{
string leaderboard = GetPlayTimeLeaderBoard(5, false, null, false, true);
playtimeLeaderBoard = leaderboard.Split(new[] {"\r\n","\n"}, StringSplitOptions.RemoveEmptyEntries);
playtimeLeaderBoard = leaderboard.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
}


Expand Down Expand Up @@ -795,16 +793,16 @@ public void ApplicationStateChange(object sender, ApplicationStateChangeEventArg

public async void UpdatePresence(object sender, ApplicationStateChangeEventArgs args, bool force = false)
{
if(_settings.MainSettings.BotActive && (args == null || args.PreviousState != args.NextState || force) && _client.ConnectionState == ConnectionState.Connected)
if (_settings.MainSettings.BotActive && (args == null || args.PreviousState != args.NextState || force) && _client.ConnectionState == ConnectionState.Connected)
{
try
{

string currentActivity = _client.Activity?.Name ?? "";
if(currentActivity != "")
if (currentActivity != "")
{
var customStatus = _client.Activity as CustomStatusGame;
if(customStatus != null)
if (customStatus != null)
{
currentActivity = customStatus.State;
}
Expand Down Expand Up @@ -841,7 +839,7 @@ public async void UpdatePresence(object sender, ApplicationStateChangeEventArgs
ClearAllPlayTimes();
}

if(status != currentStatus)
if (status != currentStatus)
{
await _client.SetStatusAsync(status);
}
Expand All @@ -851,14 +849,14 @@ public async void UpdatePresence(object sender, ApplicationStateChangeEventArgs
// Set the presence/activity based on the server state
if (application.State == ApplicationState.Ready)
{
if(currentActivity != presenceString)
if (currentActivity != presenceString)
{
await _client.SetActivityAsync(new CustomStatusGame(OnlineBotPresenceString(onlinePlayers, maximumPlayers)));
}
}
else
{
if(presenceString != application.State.ToString())
if (presenceString != application.State.ToString())
{
await _client.SetActivityAsync(new CustomStatusGame(application.State.ToString()));
}
Expand Down Expand Up @@ -1556,7 +1554,7 @@ private async Task ManageServer(SocketMessageComponent arg)
private void BackupServer(SocketGuildUser user)
{
currentUser = user;
BackupManifest manifest = new BackupManifest { ModuleName = aMPInstanceInfo.ModuleName, TakenBy = "DiscordBot", CreatedAutomatically = true, Name = "Backup Triggered by Discord Bot", Description = "Requested by " + user.Username};
BackupManifest manifest = new BackupManifest { ModuleName = aMPInstanceInfo.ModuleName, TakenBy = "DiscordBot", CreatedAutomatically = true, Name = "Backup Triggered by Discord Bot", Description = "Requested by " + user.Username };

// Register event handlers
backupProvider.BackupActionComplete += OnBackupComplete;
Expand Down Expand Up @@ -2281,16 +2279,16 @@ private string GetMemoryUsage()
totalAvailable = platform.InstalledRAMMB;
double usage = application.GetPhysicalRAMUsage();

if(usage >= 1024 || (totalAvailable > 1024 && _settings.MainSettings.ShowMaximumRAM))
if (usage >= 1024 || (totalAvailable > 1024 && _settings.MainSettings.ShowMaximumRAM))
gb = true;
if(gb)

if (gb)
{
usage = usage / 1024;
totalAvailable = totalAvailable / 1024;
}
}

if(_settings.MainSettings.ShowMaximumRAM)
if (_settings.MainSettings.ShowMaximumRAM)
{
return (usage.ToString(gb ? "N2" : "N0") + "/" + totalAvailable.ToString(gb ? "N2" : "N0") + (gb ? " GB" : "MB"));
}
Expand Down
Loading

0 comments on commit 8d8305b

Please sign in to comment.