1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-19 16:33:36 +03:00

Discord is broken lmao

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-06-16 17:28:18 +05:00
parent 0eb17a977d
commit cfa1819fd8
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
4 changed files with 22 additions and 25 deletions

View file

@ -21,7 +21,7 @@ using Remora.Results;
namespace Boyfriend.Commands;
/// <summary>
/// Handles commands related to mute management: /mute and unmute.
/// Handles commands related to mute management: /mute and /unmute.
/// </summary>
public class MuteCommandGroup : CommandGroup {
private readonly IDiscordRestChannelAPI _channelApi;
@ -65,8 +65,10 @@ public class MuteCommandGroup : CommandGroup {
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
[Description("мутит друга <3")]
public async Task<Result> MuteUserAsync(
[Description("друг которого нужно замутить ПОТОМУ-ЧТО ОН ЗАЕБАЛ")] IUser target,
[Description("причина зачем мутить друга (пиши заебал)")] string reason,
[Description("друг которого нужно замутить ПОТОМУ-ЧТО ОН ЗАЕБАЛ")]
IUser target,
[Description("причина зачем мутить друга (пиши заебал)")]
string reason,
TimeSpan duration) {
// Data checks
if (!_context.TryGetGuildID(out var guildId))
@ -82,7 +84,8 @@ public class MuteCommandGroup : CommandGroup {
return Result.FromError(currentUserResult);
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)
return Result.FromError(interactionResult);
@ -90,8 +93,6 @@ public class MuteCommandGroup : CommandGroup {
var cfg = data.Configuration;
Messages.Culture = data.Culture;
var newCoolDuration = DateTimeOffset.UtcNow.Add(duration);
Result<Embed> responseEmbed;
if (interactionResult.Entity is not null) {
responseEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, currentUser)
@ -101,9 +102,10 @@ public class MuteCommandGroup : CommandGroup {
if (!userResult.IsDefined(out var user))
return Result.FromError(userResult);
var until = DateTimeOffset.UtcNow.Add(duration); // >:)
var muteResult = await _guildApi.ModifyGuildMemberAsync(
guildId.Value, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(),
communicationDisabledUntil: newCoolDuration, ct: CancellationToken);
communicationDisabledUntil: until, ct: CancellationToken);
if (!muteResult.IsSuccess)
return Result.FromError(muteResult.Error);
@ -113,10 +115,10 @@ public class MuteCommandGroup : CommandGroup {
if ((cfg.PublicFeedbackChannel is not 0 && cfg.PublicFeedbackChannel != channelId.Value)
|| (cfg.PrivateFeedbackChannel is not 0 && cfg.PrivateFeedbackChannel != channelId.Value)) {
var builder = new StringBuilder().AppendLine(string.Format(Messages.DescriptionActionReason, reason));
builder.Append(
var builder = new StringBuilder().AppendLine(string.Format(Messages.DescriptionActionReason, reason))
.Append(
string.Format(
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(newCoolDuration)));
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(until)));
var logEmbed = new EmbedBuilder().WithSmallTitle(
string.Format(Messages.UserMuted, target.GetTag()), target)
@ -163,7 +165,7 @@ public class MuteCommandGroup : CommandGroup {
/// </returns>
/// <seealso cref="MuteUserAsync" />
/// <seealso cref="GuildUpdateService.TickGuildAsync"/>
[Command("unmute")]
[Command("unmute", "размут")]
[RequireContext(ChannelContext.Guild)]
[RequireDiscordPermission(DiscordPermission.ModerateMembers)]
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
@ -185,7 +187,8 @@ public class MuteCommandGroup : CommandGroup {
var cfg = await _dataService.GetConfiguration(guildId.Value, CancellationToken);
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) {
var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotMuted, currentUser)
.WithColour(ColorsList.Red).Build();

View file

@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Text.Json;
using Boyfriend.Data;
using Microsoft.Extensions.Hosting;
@ -11,9 +12,9 @@ namespace Boyfriend.Services.Data;
/// Handles saving, loading, initializing and providing <see cref="GuildData" />.
/// </summary>
public class GuildDataService : IHostedService {
private readonly Dictionary<Snowflake, GuildData> _datas = new();
private readonly IDiscordRestGuildAPI _guildApi;
private readonly ILogger<GuildDataService> _logger;
private readonly ConcurrentDictionary<Snowflake, GuildData> _datas = new();
private readonly IDiscordRestGuildAPI _guildApi;
private readonly ILogger<GuildDataService> _logger;
// https://github.com/dotnet/aspnetcore/issues/39139
public GuildDataService(
@ -85,8 +86,6 @@ public class GuildDataService : IHostedService {
var memberResult = await _guildApi.GetGuildMemberAsync(guildId, data.Id.ToDiscordSnowflake(), ct);
if (memberResult.IsSuccess)
data.Roles = memberResult.Entity.Roles.ToList();
else
_logger.LogWarning("Error in member retrieval.\n{ErrorMessage}", memberResult.Error.Message);
memberData.Add(data.Id, data);
}
@ -95,7 +94,7 @@ public class GuildDataService : IHostedService {
await configuration ?? new GuildConfiguration(), configurationPath,
await events ?? new Dictionary<ulong, ScheduledEventData>(), scheduledEventsPath,
memberData, memberDataPath);
_datas.Add(guildId, finalData);
while (!_datas.ContainsKey(guildId)) _datas.TryAdd(guildId, finalData);
return finalData;
}

View file

@ -87,14 +87,9 @@ public class GuildUpdateService : BackgroundService {
foreach (var memberData in data.MemberData.Values) {
var userIdSnowflake = memberData.Id.ToDiscordSnowflake();
if (!memberData.Roles.Contains(defaultRoleSnowflake)) {
var defaultRoleResult = await _guildApi.AddGuildMemberRoleAsync(
if (defaultRoleSnowflake.Value is not 0 && !memberData.Roles.Contains(defaultRoleSnowflake))
_ = _guildApi.AddGuildMemberRoleAsync(
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) {
var unbanResult = await _guildApi.RemoveGuildBanAsync(