mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-01 03:29:54 +03:00
Apply official naming guidelines to Octobot (#306)
1. The root namespace was changed from `Octobot` to `TeamOctolings.Octobot`: > DO prefix namespace names with a company name to prevent namespaces from different companies from having the same name. 2. `Octobot.cs` was renamed to `Program.cs`: > DO NOT use the same name for a namespace and a type in that namespace. 3. `IOption`, `Option` were renamed to `IGuildOption` and `GuildOption` respectively: > DO NOT introduce generic type names such as Element, Node, Log, and Message. 4. `Utility` was moved out of the `Services` namespace. It didn't belong there anyway 5. `Program` static fields were moved to `Utility` 6. Localisation files were moved back to the project source files. Looks like this fixed `Message.Designer.cs` code generation --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
19fadead91
commit
793afd0e06
61 changed files with 447 additions and 462 deletions
72
TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs
Normal file
72
TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using JetBrains.Annotations;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||
using Remora.Discord.API.Abstractions.Rest;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Discord.Gateway.Responders;
|
||||
using Remora.Results;
|
||||
using TeamOctolings.Octobot.Data;
|
||||
using TeamOctolings.Octobot.Extensions;
|
||||
using TeamOctolings.Octobot.Services;
|
||||
|
||||
namespace TeamOctolings.Octobot.Responders;
|
||||
|
||||
/// <summary>
|
||||
/// Handles sending a guild's <see cref="GuildSettings.LeaveMessage" /> if one is set.
|
||||
/// </summary>
|
||||
/// <seealso cref="GuildSettings.LeaveMessage" />
|
||||
[UsedImplicitly]
|
||||
public class GuildMemberLeftResponder : IResponder<IGuildMemberRemove>
|
||||
{
|
||||
private readonly IDiscordRestChannelAPI _channelApi;
|
||||
private readonly IDiscordRestGuildAPI _guildApi;
|
||||
private readonly GuildDataService _guildData;
|
||||
|
||||
public GuildMemberLeftResponder(
|
||||
IDiscordRestChannelAPI channelApi, GuildDataService guildData, IDiscordRestGuildAPI guildApi)
|
||||
{
|
||||
_channelApi = channelApi;
|
||||
_guildData = guildData;
|
||||
_guildApi = guildApi;
|
||||
}
|
||||
|
||||
public async Task<Result> RespondAsync(IGuildMemberRemove gatewayEvent, CancellationToken ct = default)
|
||||
{
|
||||
var user = gatewayEvent.User;
|
||||
var data = await _guildData.GetData(gatewayEvent.GuildID, ct);
|
||||
var cfg = data.Settings;
|
||||
|
||||
var memberData = data.GetOrCreateMemberData(user.ID);
|
||||
if (memberData.BannedUntil is not null || memberData.Kicked)
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
if (GuildSettings.WelcomeMessagesChannel.Get(cfg).Empty()
|
||||
|| GuildSettings.LeaveMessage.Get(cfg) is "off" or "disable" or "disabled")
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
Messages.Culture = GuildSettings.Language.Get(cfg);
|
||||
var leaveMessage = GuildSettings.LeaveMessage.Get(cfg) is "default" or "reset"
|
||||
? Messages.DefaultLeaveMessage
|
||||
: GuildSettings.LeaveMessage.Get(cfg);
|
||||
|
||||
var guildResult = await _guildApi.GetGuildAsync(gatewayEvent.GuildID, ct: ct);
|
||||
if (!guildResult.IsDefined(out var guild))
|
||||
{
|
||||
return ResultExtensions.FromError(guildResult);
|
||||
}
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
.WithSmallTitle(string.Format(leaveMessage, user.GetTag(), guild.Name), user)
|
||||
.WithGuildFooter(guild)
|
||||
.WithTimestamp(DateTimeOffset.UtcNow)
|
||||
.WithColour(ColorsList.Black)
|
||||
.Build();
|
||||
|
||||
return await _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
GuildSettings.WelcomeMessagesChannel.Get(cfg), embedResult: embed,
|
||||
allowedMentions: Utility.NoMentions, ct: ct);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue