Skip to content

Commit

Permalink
feat: add seperate guilds
Browse files Browse the repository at this point in the history
  • Loading branch information
JayXTQ committed Dec 9, 2024
1 parent 5a095bd commit ae801f5
Show file tree
Hide file tree
Showing 28 changed files with 188 additions and 55 deletions.
2 changes: 2 additions & 0 deletions DiscordLab.AdvancedLogging/Commands/AddLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class AddLog : ISlashCommand
Description = "Add your own custom logger, check the documentation for more info",
DefaultMemberPermissions = GuildPermission.ManageGuild
};

public ulong GuildId { get; set; } = Plugin.Instance.Config.GuildId;

public async Task Run(SocketSlashCommand command)
{
Expand Down
2 changes: 2 additions & 0 deletions DiscordLab.AdvancedLogging/Commands/RemoveLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class RemoveLog : ISlashCommand
}
}
};

public ulong GuildId { get; set; } = Plugin.Instance.Config.GuildId;

public async Task Run(SocketSlashCommand command)
{
Expand Down
9 changes: 8 additions & 1 deletion DiscordLab.AdvancedLogging/Config.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using System.ComponentModel;
using DiscordLab.Bot.API.Features;
using DiscordLab.Bot.API.Interfaces;
using Exiled.API.Interfaces;

namespace DiscordLab.AdvancedLogging
{
public class Config : IConfig
public class Config : IConfig, IDLConfig
{
[Description(DescriptionConstants.IsEnabled)]
public bool IsEnabled { get; set; } = true;
[Description(DescriptionConstants.Debug)]
public bool Debug { get; set; } = false;
[Description(DescriptionConstants.GuildId)]
public ulong GuildId { get; set; }
}
}
5 changes: 3 additions & 2 deletions DiscordLab.AdvancedLogging/Handlers/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ private void RemoveEventHandlers()

private SocketTextChannel GetChannel(ulong channelId)
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = Bot.Handlers.DiscordBot.Instance.GetGuild(Plugin.Instance.Config.GuildId);
if (guild == null) return null;
if (Channels.Exists(c => c.ChannelId == channelId))
return Channels.First(c => c.ChannelId == channelId).Channel;
SocketTextChannel channel = Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(channelId);
SocketTextChannel channel = guild.GetTextChannel(channelId);
if (channel != null) return channel;
Log.Error("Either the guild is null or the channel is null. So the status message has failed to send.");
return null;
Expand Down
9 changes: 9 additions & 0 deletions DiscordLab.Bot/API/Features/DescriptionConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DiscordLab.Bot.API.Features
{
public class DescriptionConstants
{
public const string GuildId = "The guild ID where this module will be used. If not set (value = 0), it will use the default guild ID.";
public const string IsEnabled = "Whether the module is enabled or not.";
public const string Debug = "Whether the module is in debug mode or not.";
}
}
10 changes: 10 additions & 0 deletions DiscordLab.Bot/API/Interfaces/IDLConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.ComponentModel;

namespace DiscordLab.Bot.API.Interfaces
{

public interface IDLConfig
{
public ulong GuildId { get; set; }
}
}
9 changes: 7 additions & 2 deletions DiscordLab.Bot/API/Interfaces/ISlashCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ public interface ISlashCommand
/// <summary>
/// Here you create your <see cref="SlashCommandBuilder"/> with the data of your command.
/// </summary>
SlashCommandBuilder Data { get; }
public SlashCommandBuilder Data { get; }

/// <summary>
/// Set the GuildId where the command should be created here, you should reference Config.GuildId.
/// </summary>
public ulong GuildId { get; set; }

/// <summary>
/// Here is where your slash command runs.
/// </summary>
/// <remarks>
/// This type contains information about the command that was executed.
/// </remarks>
Task Run(SocketSlashCommand command);
public Task Run(SocketSlashCommand command);
}
}
6 changes: 3 additions & 3 deletions DiscordLab.Bot/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class Config : IConfig
{
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;
[Description("The token of the bot.")] public string Token { get; set; } = "token";

[Description("The guild where the bot will be used.")]
[Description("The token of the bot.")]
public string Token { get; set; } = "token";
[Description("The default guild where the bot will be used. You can set this individually for each module, but if a module doesn't have a guild id set, it will use this one.")]
public ulong GuildId { get; set; } = new();
}
}
12 changes: 9 additions & 3 deletions DiscordLab.Bot/Handlers/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DiscordBot : IRegisterable

public DiscordSocketClient Client { get; private set; }

public SocketGuild Guild;
private SocketGuild _guild;

public void Init()
{
Expand Down Expand Up @@ -54,14 +54,20 @@ private async Task StopClient()
await Client.StopAsync();
}

public SocketGuild GetGuild(ulong id)
{
return id == 0 ? _guild : Client.GetGuild(id);
}

private async Task Ready()
{
Guild = Client.GetGuild(Plugin.Instance.Config.GuildId);
_guild = Client.GetGuild(Plugin.Instance.Config.GuildId);
foreach (ISlashCommand command in SlashCommandLoader.Commands)
{
try
{
await Guild.CreateApplicationCommandAsync(command.Data.Build());
SocketGuild guild = GetGuild(command.GuildId);
await guild.CreateApplicationCommandAsync(command.Data.Build());
}
catch (Exception e)
{
Expand Down
3 changes: 3 additions & 0 deletions DiscordLab.BotStatus/Config.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.ComponentModel;
using DiscordLab.Bot.API.Features;
using Exiled.API.Interfaces;

namespace DiscordLab.BotStatus
{
public class Config : IConfig
{
[Description(DescriptionConstants.IsEnabled)]
public bool IsEnabled { get; set; } = true;
[Description(DescriptionConstants.Debug)]
public bool Debug { get; set; } = false;

[Description("Set the Discord bot's status to orange when the server is empty.")]
Expand Down
10 changes: 9 additions & 1 deletion DiscordLab.ConnectionLogs/Config.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using System.ComponentModel;
using DiscordLab.Bot.API.Features;
using DiscordLab.Bot.API.Interfaces;
using Exiled.API.Interfaces;

namespace DiscordLab.ConnectionLogs
{
public class Config : IConfig
public class Config : IConfig, IDLConfig
{
[Description(DescriptionConstants.IsEnabled)]
public bool IsEnabled { get; set; } = true;

[Description(DescriptionConstants.Debug)]
public bool Debug { get; set; } = false;

[Description("The channel where the join logs will be sent.")]
Expand All @@ -16,5 +21,8 @@ public class Config : IConfig

[Description("The channel where the round start logs will be sent.")]
public ulong RoundStartChannelId { get; set; } = new();

[Description(DescriptionConstants.GuildId)]
public ulong GuildId { get; set; }
}
}
20 changes: 14 additions & 6 deletions DiscordLab.ConnectionLogs/Handlers/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,37 @@ public void Unregister()
LeaveChannel = null;
RoundStartChannel = null;
}

public SocketGuild GetGuild()
{
return Bot.Handlers.DiscordBot.Instance.Client.GetGuild(Plugin.Instance.Config.GuildId);
}

public SocketTextChannel GetJoinChannel()
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = GetGuild();
if (guild == null) return null;
if (Plugin.Instance.Config.JoinChannelId == 0) return null;
return JoinChannel ??=
Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(Plugin.Instance.Config.JoinChannelId);
guild.GetTextChannel(Plugin.Instance.Config.JoinChannelId);
}

public SocketTextChannel GetLeaveChannel()
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = GetGuild();
if (guild == null) return null;
if (Plugin.Instance.Config.LeaveChannelId == 0) return null;
return LeaveChannel ??=
Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(Plugin.Instance.Config.LeaveChannelId);
guild.GetTextChannel(Plugin.Instance.Config.LeaveChannelId);
}

public SocketTextChannel GetRoundStartChannel()
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = GetGuild();
if (guild == null) return null;
if (Plugin.Instance.Config.RoundStartChannelId == 0) return null;
return RoundStartChannel ??=
Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(Plugin.Instance.Config.RoundStartChannelId);
guild.GetTextChannel(Plugin.Instance.Config.RoundStartChannelId);
}
}
}
9 changes: 8 additions & 1 deletion DiscordLab.DeathLogs/Config.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System.ComponentModel;
using DiscordLab.Bot.API.Features;
using DiscordLab.Bot.API.Interfaces;
using Exiled.API.Interfaces;

namespace DiscordLab.DeathLogs
{
public class Config : IConfig
public class Config : IConfig, IDLConfig
{
[Description(DescriptionConstants.IsEnabled)]
public bool IsEnabled { get; set; } = true;
[Description(DescriptionConstants.Debug)]
public bool Debug { get; set; } = false;

[Description("The channel where the normal death logs will be sent.")]
Expand All @@ -24,5 +28,8 @@ public class Config : IConfig

[Description("If this is true, then the plugin will ignore the cuff state of the player and send the death logs to the normal death logs channel.")]
public bool ScpIgnoreCuffed { get; set; } = true;

[Description(DescriptionConstants.GuildId)]
public ulong GuildId { get; set; }
}
}
25 changes: 17 additions & 8 deletions DiscordLab.DeathLogs/Handlers/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,45 @@ public void Unregister()
SelfChannel = null;
TeamKillChannel = null;
}

public SocketGuild GetGuild()
{
return Bot.Handlers.DiscordBot.Instance.Client.GetGuild(Plugin.Instance.Config.GuildId);
}

public SocketTextChannel GetChannel()
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = GetGuild();
if (GetGuild() == null) return null;
if (Plugin.Instance.Config.ChannelId == 0) return null;
return Channel ??= Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(Plugin.Instance.Config.ChannelId);
return Channel ??= guild.GetTextChannel(Plugin.Instance.Config.ChannelId);
}

public SocketTextChannel GetCuffedChannel()
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = GetGuild();
if (guild == null) return null;
if (Plugin.Instance.Config.CuffedChannelId == 0) return null;
return CuffedChannel ??=
Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(Plugin.Instance.Config.CuffedChannelId);
guild.GetTextChannel(Plugin.Instance.Config.CuffedChannelId);
}

public SocketTextChannel GetSelfChannel()
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = GetGuild();
if (guild == null) return null;
if (Plugin.Instance.Config.SelfChannelId == 0) return null;
return SelfChannel ??=
Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(Plugin.Instance.Config.SelfChannelId);
guild.GetTextChannel(Plugin.Instance.Config.SelfChannelId);
}

public SocketTextChannel GetTeamKillChannel()
{
if (Bot.Handlers.DiscordBot.Instance.Guild == null) return null;
SocketGuild guild = GetGuild();
if (guild == null) return null;
if (Plugin.Instance.Config.TeamKillChannelId == 0) return null;
return TeamKillChannel ??=
Bot.Handlers.DiscordBot.Instance.Guild.GetTextChannel(Plugin.Instance.Config.TeamKillChannelId);
guild.GetTextChannel(Plugin.Instance.Config.TeamKillChannelId);
}
}
}
4 changes: 3 additions & 1 deletion DiscordLab.Moderation/Commands/Ban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class Ban : ISlashCommand
}
}
};

public ulong GuildId { get; set; } = Plugin.Instance.Config.GuildId;

public async Task Run(SocketSlashCommand command)
{
Expand All @@ -50,7 +52,7 @@ public async Task Run(SocketSlashCommand command)
string duration = command.Data.Options
.First(option => option.Name == Translation.BanCommandDurationOptionName).Value.ToString();

string response = Server.ExecuteCommand($"oban {user} {duration} {reason}");
string response = Server.ExecuteCommand($"/oban {user} {duration} {reason}");
if (!response.Contains("has been banned"))
{
await command.RespondAsync(Translation.FailedExecuteCommand.Replace("{reason}", response),
Expand Down
2 changes: 2 additions & 0 deletions DiscordLab.Moderation/Commands/SendCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class SendCommand : ISlashCommand
}
};

public ulong GuildId { get; set; } = Plugin.Instance.Config.GuildId;

public async Task Run(SocketSlashCommand command)
{
string commandToExecute = command.Data.Options.First(option => option.Name == Translation.SendCommandCommandOptionName)
Expand Down
4 changes: 3 additions & 1 deletion DiscordLab.Moderation/Commands/Unban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public class Unban : ISlashCommand
}
}
};

public ulong GuildId { get; set; } = Plugin.Instance.Config.GuildId;

public async Task Run(SocketSlashCommand command)
{
string user = command.Data.Options.First(option => option.Name == Translation.BanCommandUserOptionName)
.Value.ToString();

string response = Server.ExecuteCommand($"unban id {user}");
string response = Server.ExecuteCommand($"/unban id {user}");
if (!response.Contains("Done"))
{
await command.RespondAsync(Translation.FailedExecuteCommand.Replace("{reason}", response),
Expand Down
12 changes: 10 additions & 2 deletions DiscordLab.Moderation/Config.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using Exiled.API.Interfaces;
using System.ComponentModel;
using DiscordLab.Bot.API.Features;
using DiscordLab.Bot.API.Interfaces;
using Exiled.API.Interfaces;

namespace DiscordLab.Moderation
{
public class Config : IConfig
public class Config : IConfig, IDLConfig
{
[Description(DescriptionConstants.IsEnabled)]
public bool IsEnabled { get; set; } = true;
[Description(DescriptionConstants.Debug)]
public bool Debug { get; set; } = false;

[Description(DescriptionConstants.GuildId)]
public ulong GuildId { get; set; }
}
}
Loading

0 comments on commit ae801f5

Please sign in to comment.