Beispiel #1
0
        public async Task <int> RemoveModerationActionAsync(ModerationAction action)
        {
            using (var scope = _services.CreateScope())
            {
                var _db = scope.ServiceProvider.GetRequiredService <EntityContext>();

                var actions = _db.ModerationActions;
                var query   = actions.Where(x => x.GuildId == action.GuildId);
                ModerationActionCollection list;
                if (!query.Any())
                {
                    list = new ModerationActionCollection {
                        GuildId = action.GuildId
                    };
                    actions.Add(list);
                }
                else
                {
                    list = query.Single();
                }

                if (list.Contains(action))
                {
                    list.Remove(action);
                }
                return(await _db.SaveChangesAsync());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Moderates the topic with the specified action.
        /// </summary>
        /// <param name="action">The action to perform. You need to have sufficient permission for it.</param>
        /// <param name="reason">The reason for moderation.</param>
        /// <param name="cancellationToken">A token used to cancel the operation.</param>
        /// <remarks>This method will not update <see cref="TopicTitleRevision"/> content, you need to call <see cref="RefreshAsync()"/> if you need the latest revision information.</remarks>
        public async Task ModerateAsync(ModerationAction action, string reason, CancellationToken cancellationToken)
        {
            if (reason == null)
            {
                throw new ArgumentNullException(nameof(reason));
            }
            if (reason.Length == 0)
            {
                throw new ArgumentException("Reason cannot be empty.", nameof(reason));
            }
            JToken jresult;

            using (await Site.ModificationThrottler.QueueWorkAsync("Moderate: " + WorkflowId, cancellationToken))
            {
                jresult = await Site.InvokeMediaWikiApiAsync(new MediaWikiFormRequestMessage(new
                {
                    action = "flow",
                    submodule = "moderate-topic",
                    token = WikiSiteToken.Edit,
                    page = Title,
                    mtmoderationState = EnumParser.ToString(action),
                    mtreason = reason,
                }), cancellationToken);
            }
        }
        public async Task <MuteResult> TryMuteUserAsync(SocketGuildUser moderator, SocketGuildUser user, string reason = null, TimeSpan?expiry = null)
        {
            try
            {
                if (user.TimedOutUntil is not null && user.TimedOutUntil.Value.UtcDateTime > DateTime.UtcNow)
                {
                    return(MuteResult.FromError("The user is already under a timeout.", user.Id));
                }

                if (expiry is null || expiry > TimeSpan.FromDays(28))
                {
                    expiry = TimeSpan.FromDays(28);
                }

                await user.SetTimeOutAsync(expiry.Value, new RequestOptions { AuditLogReason = reason });

                var action = new ModerationAction(user.Id, moderator.Id, user.Guild.Id, merlin.classes.ActionType.Mute, expiry, reason);
                AddAction(action);

                return(MuteResult.FromSuccess(action));
            }
            catch (Exception e)
            {
                return(MuteResult.FromError($"There was an exception while adding a timeout to the user. ({e.Message})", user.Id));
            }
        }
 public void LogModerationAction(ModerationAction action)
 {
     using (var conn = _connectionProvider.GetConnection())
     {
         conn.Insert(action);
     }
 }
Beispiel #5
0
 public int RemoveAction(ModerationAction action) => _db
 .GetCollection <ModerationAction>("actions")
 .Delete(Query
         .And(
             Query.EQ("GuildId", action.GuildId),
             Query.EQ("ModeratorId", action.ModeratorId),
             Query.EQ("UserId", action.UserId),
             Query.EQ("Type", (int)action.Type)
             )
         );
Beispiel #6
0
 public static string ToString(ModerationAction value)
 {
     return(value switch
     {
         ModerationAction.Delete => "delete",
         ModerationAction.Hide => "hide",
         ModerationAction.Suppress => "suppress",
         ModerationAction.Restore => "restore",
         ModerationAction.Unhide => "unhide",
         ModerationAction.Undelete => "undelete",
         ModerationAction.Unsuppress => "unsuppress",
         _ => throw new ArgumentOutOfRangeException(nameof(value), value, null)
     });
Beispiel #7
0
        public static string ToString(ModerationAction value)
        {
            switch (value)
            {
            case ModerationAction.Delete: return("delete");

            case ModerationAction.Hide: return("hide");

            case ModerationAction.Suppress: return("suppress");

            case ModerationAction.Restore: return("restore");

            case ModerationAction.Unhide: return("unhide");

            case ModerationAction.Undelete: return("undelete");

            case ModerationAction.Unsuppress: return("unsuppress");

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value, null);
            }
        }
Beispiel #8
0
 public static MuteResult FromSuccess(ModerationAction action) => new MuteResult(action);
Beispiel #9
0
 private MuteResult(ModerationAction action)
 {
     Action    = action;
     UserId    = action.UserId;
     IsSuccess = true;
 }
Beispiel #10
0
 public ModerationActionControl(ActionContainerControl containerControl, ModerationAction action) : this(containerControl) { this.action = action; }
Beispiel #11
0
 /// <inheritdoc cref="ModerateAsync(ModerationAction,string,CancellationToken)"/>
 public Task ModerateAsync(ModerationAction action, string reason)
 {
     return(ModerateAsync(action, reason, CancellationToken.None));
 }
 public ModerationActionControl(ModerationAction action) : this()
 {
     this.action = action;
 }
Beispiel #13
0
 public bool AddAction(ModerationAction action) => _db
 .GetCollection <ModerationAction>("actions")
 .Upsert(action);
 public void RemoveAction(ModerationAction action)
 {
     _actions.Remove(action);
     _db.RemoveAction(action);
 }
 public void AddAction(ModerationAction action)
 {
     _actions.Add(action);
     _db.AddAction(action);
 }
Beispiel #16
0
 private void LogAction(ModerationAction action)
 {
     _moderationRepository.LogModerationAction(action);
 }