mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
Discord is broken lmao
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
0eb17a977d
commit
cfa1819fd8
4 changed files with 22 additions and 25 deletions
|
@ -21,7 +21,7 @@ using Remora.Results;
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles commands related to mute management: /mute and unmute.
|
/// Handles commands related to mute management: /mute and /unmute.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MuteCommandGroup : CommandGroup {
|
public class MuteCommandGroup : CommandGroup {
|
||||||
private readonly IDiscordRestChannelAPI _channelApi;
|
private readonly IDiscordRestChannelAPI _channelApi;
|
||||||
|
@ -65,8 +65,10 @@ public class MuteCommandGroup : CommandGroup {
|
||||||
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
|
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
|
||||||
[Description("мутит друга <3")]
|
[Description("мутит друга <3")]
|
||||||
public async Task<Result> MuteUserAsync(
|
public async Task<Result> MuteUserAsync(
|
||||||
[Description("друг которого нужно замутить ПОТОМУ-ЧТО ОН ЗАЕБАЛ")] IUser target,
|
[Description("друг которого нужно замутить ПОТОМУ-ЧТО ОН ЗАЕБАЛ")]
|
||||||
[Description("причина зачем мутить друга (пиши заебал)")] string reason,
|
IUser target,
|
||||||
|
[Description("причина зачем мутить друга (пиши заебал)")]
|
||||||
|
string reason,
|
||||||
TimeSpan duration) {
|
TimeSpan duration) {
|
||||||
// Data checks
|
// Data checks
|
||||||
if (!_context.TryGetGuildID(out var guildId))
|
if (!_context.TryGetGuildID(out var guildId))
|
||||||
|
@ -82,7 +84,8 @@ public class MuteCommandGroup : CommandGroup {
|
||||||
return Result.FromError(currentUserResult);
|
return Result.FromError(currentUserResult);
|
||||||
|
|
||||||
var interactionResult
|
var interactionResult
|
||||||
= await _utility.CheckInteractionsAsync(guildId.Value, userId.Value, target.ID, "Timeout", CancellationToken);
|
= await _utility.CheckInteractionsAsync(
|
||||||
|
guildId.Value, userId.Value, target.ID, "Timeout", CancellationToken);
|
||||||
if (!interactionResult.IsSuccess)
|
if (!interactionResult.IsSuccess)
|
||||||
return Result.FromError(interactionResult);
|
return Result.FromError(interactionResult);
|
||||||
|
|
||||||
|
@ -90,8 +93,6 @@ public class MuteCommandGroup : CommandGroup {
|
||||||
var cfg = data.Configuration;
|
var cfg = data.Configuration;
|
||||||
Messages.Culture = data.Culture;
|
Messages.Culture = data.Culture;
|
||||||
|
|
||||||
var newCoolDuration = DateTimeOffset.UtcNow.Add(duration);
|
|
||||||
|
|
||||||
Result<Embed> responseEmbed;
|
Result<Embed> responseEmbed;
|
||||||
if (interactionResult.Entity is not null) {
|
if (interactionResult.Entity is not null) {
|
||||||
responseEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, currentUser)
|
responseEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, currentUser)
|
||||||
|
@ -101,9 +102,10 @@ public class MuteCommandGroup : CommandGroup {
|
||||||
if (!userResult.IsDefined(out var user))
|
if (!userResult.IsDefined(out var user))
|
||||||
return Result.FromError(userResult);
|
return Result.FromError(userResult);
|
||||||
|
|
||||||
|
var until = DateTimeOffset.UtcNow.Add(duration); // >:)
|
||||||
var muteResult = await _guildApi.ModifyGuildMemberAsync(
|
var muteResult = await _guildApi.ModifyGuildMemberAsync(
|
||||||
guildId.Value, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(),
|
guildId.Value, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(),
|
||||||
communicationDisabledUntil: newCoolDuration, ct: CancellationToken);
|
communicationDisabledUntil: until, ct: CancellationToken);
|
||||||
if (!muteResult.IsSuccess)
|
if (!muteResult.IsSuccess)
|
||||||
return Result.FromError(muteResult.Error);
|
return Result.FromError(muteResult.Error);
|
||||||
|
|
||||||
|
@ -113,10 +115,10 @@ public class MuteCommandGroup : CommandGroup {
|
||||||
|
|
||||||
if ((cfg.PublicFeedbackChannel is not 0 && cfg.PublicFeedbackChannel != channelId.Value)
|
if ((cfg.PublicFeedbackChannel is not 0 && cfg.PublicFeedbackChannel != channelId.Value)
|
||||||
|| (cfg.PrivateFeedbackChannel is not 0 && cfg.PrivateFeedbackChannel != channelId.Value)) {
|
|| (cfg.PrivateFeedbackChannel is not 0 && cfg.PrivateFeedbackChannel != channelId.Value)) {
|
||||||
var builder = new StringBuilder().AppendLine(string.Format(Messages.DescriptionActionReason, reason));
|
var builder = new StringBuilder().AppendLine(string.Format(Messages.DescriptionActionReason, reason))
|
||||||
builder.Append(
|
.Append(
|
||||||
string.Format(
|
string.Format(
|
||||||
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(newCoolDuration)));
|
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(until)));
|
||||||
|
|
||||||
var logEmbed = new EmbedBuilder().WithSmallTitle(
|
var logEmbed = new EmbedBuilder().WithSmallTitle(
|
||||||
string.Format(Messages.UserMuted, target.GetTag()), target)
|
string.Format(Messages.UserMuted, target.GetTag()), target)
|
||||||
|
@ -163,7 +165,7 @@ public class MuteCommandGroup : CommandGroup {
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <seealso cref="MuteUserAsync" />
|
/// <seealso cref="MuteUserAsync" />
|
||||||
/// <seealso cref="GuildUpdateService.TickGuildAsync"/>
|
/// <seealso cref="GuildUpdateService.TickGuildAsync"/>
|
||||||
[Command("unmute")]
|
[Command("unmute", "размут")]
|
||||||
[RequireContext(ChannelContext.Guild)]
|
[RequireContext(ChannelContext.Guild)]
|
||||||
[RequireDiscordPermission(DiscordPermission.ModerateMembers)]
|
[RequireDiscordPermission(DiscordPermission.ModerateMembers)]
|
||||||
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
|
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
|
||||||
|
@ -185,7 +187,8 @@ public class MuteCommandGroup : CommandGroup {
|
||||||
var cfg = await _dataService.GetConfiguration(guildId.Value, CancellationToken);
|
var cfg = await _dataService.GetConfiguration(guildId.Value, CancellationToken);
|
||||||
Messages.Culture = cfg.GetCulture();
|
Messages.Culture = cfg.GetCulture();
|
||||||
|
|
||||||
var existingMuteResult = await _guildApi.ModifyGuildMemberAsync(guildId.Value, target.ID, communicationDisabledUntil: DateTimeOffset.UtcNow);
|
var existingMuteResult = await _guildApi.ModifyGuildMemberAsync(
|
||||||
|
guildId.Value, target.ID, communicationDisabledUntil: DateTimeOffset.UtcNow);
|
||||||
if (!existingMuteResult.IsSuccess) {
|
if (!existingMuteResult.IsSuccess) {
|
||||||
var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotMuted, currentUser)
|
var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotMuted, currentUser)
|
||||||
.WithColour(ColorsList.Red).Build();
|
.WithColour(ColorsList.Red).Build();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Boyfriend.Data;
|
using Boyfriend.Data;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
@ -11,7 +12,7 @@ namespace Boyfriend.Services.Data;
|
||||||
/// Handles saving, loading, initializing and providing <see cref="GuildData" />.
|
/// Handles saving, loading, initializing and providing <see cref="GuildData" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GuildDataService : IHostedService {
|
public class GuildDataService : IHostedService {
|
||||||
private readonly Dictionary<Snowflake, GuildData> _datas = new();
|
private readonly ConcurrentDictionary<Snowflake, GuildData> _datas = new();
|
||||||
private readonly IDiscordRestGuildAPI _guildApi;
|
private readonly IDiscordRestGuildAPI _guildApi;
|
||||||
private readonly ILogger<GuildDataService> _logger;
|
private readonly ILogger<GuildDataService> _logger;
|
||||||
|
|
||||||
|
@ -85,8 +86,6 @@ public class GuildDataService : IHostedService {
|
||||||
var memberResult = await _guildApi.GetGuildMemberAsync(guildId, data.Id.ToDiscordSnowflake(), ct);
|
var memberResult = await _guildApi.GetGuildMemberAsync(guildId, data.Id.ToDiscordSnowflake(), ct);
|
||||||
if (memberResult.IsSuccess)
|
if (memberResult.IsSuccess)
|
||||||
data.Roles = memberResult.Entity.Roles.ToList();
|
data.Roles = memberResult.Entity.Roles.ToList();
|
||||||
else
|
|
||||||
_logger.LogWarning("Error in member retrieval.\n{ErrorMessage}", memberResult.Error.Message);
|
|
||||||
|
|
||||||
memberData.Add(data.Id, data);
|
memberData.Add(data.Id, data);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +94,7 @@ public class GuildDataService : IHostedService {
|
||||||
await configuration ?? new GuildConfiguration(), configurationPath,
|
await configuration ?? new GuildConfiguration(), configurationPath,
|
||||||
await events ?? new Dictionary<ulong, ScheduledEventData>(), scheduledEventsPath,
|
await events ?? new Dictionary<ulong, ScheduledEventData>(), scheduledEventsPath,
|
||||||
memberData, memberDataPath);
|
memberData, memberDataPath);
|
||||||
_datas.Add(guildId, finalData);
|
while (!_datas.ContainsKey(guildId)) _datas.TryAdd(guildId, finalData);
|
||||||
return finalData;
|
return finalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,14 +87,9 @@ public class GuildUpdateService : BackgroundService {
|
||||||
|
|
||||||
foreach (var memberData in data.MemberData.Values) {
|
foreach (var memberData in data.MemberData.Values) {
|
||||||
var userIdSnowflake = memberData.Id.ToDiscordSnowflake();
|
var userIdSnowflake = memberData.Id.ToDiscordSnowflake();
|
||||||
if (!memberData.Roles.Contains(defaultRoleSnowflake)) {
|
if (defaultRoleSnowflake.Value is not 0 && !memberData.Roles.Contains(defaultRoleSnowflake))
|
||||||
var defaultRoleResult = await _guildApi.AddGuildMemberRoleAsync(
|
_ = _guildApi.AddGuildMemberRoleAsync(
|
||||||
guildId, userIdSnowflake, defaultRoleSnowflake, ct: ct);
|
guildId, userIdSnowflake, defaultRoleSnowflake, ct: ct);
|
||||||
if (!defaultRoleResult.IsSuccess)
|
|
||||||
_logger.LogWarning(
|
|
||||||
"Error in automatic default role add request.\n{ErrorMessage}",
|
|
||||||
defaultRoleResult.Error.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DateTimeOffset.UtcNow > memberData.BannedUntil) {
|
if (DateTimeOffset.UtcNow > memberData.BannedUntil) {
|
||||||
var unbanResult = await _guildApi.RemoveGuildBanAsync(
|
var unbanResult = await _guildApi.RemoveGuildBanAsync(
|
||||||
|
|
Loading…
Add table
Reference in a new issue