public async Task SetNickname(SocketGuildUser user = null, [Remainder] string nickname = "")
        {
            if (user == null)
            {
                await BetterReplyAsync("You must mention a user to set their nickname.", parameters : $"user null; {nickname}");

                return;
            }

            if (string.IsNullOrWhiteSpace(nickname))
            {
                await BetterReplyAsync($"You did not specify a nickname to set for `{user}`.", parameters : $"{user} ({user.Id}); {nickname}");

                return;
            }

            if (WubbysFunHouse.IsDiscordStaff(user))
            {
                await BetterReplyAsync("You can not set the nickname of another staff member.", parameters : $"{user} ({user.Id}); {nickname}");

                return;
            }

            string orginalUserName = BetterUserFormat(user);

            await user.ModifyAsync(x => { x.Nickname = nickname; }, new RequestOptions { AuditLogReason = $"Changed by {Context.User} ({Context.User.Id})" });

            await BetterReplyAsync($"Changed nickname for {orginalUserName} to `{nickname}`.", parameters : $"{user} ({user.Id}); {nickname}");
        }
Example #2
0
 public async Task Unmute(SocketUser user = null)
 {
     if (user is SocketGuildUser guildUser)
     {
         await WubbysFunHouse.RemoveRoleAsync(guildUser, WubbysFunHouse.MutedRoleId, $"Mute removed by {Context.User} ({Context.User.Id})");
         await BetterReplyAsync($"Force removed the MEE6 `Mute` role from `{user}`.");
     }
 }
Example #3
0
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            if (context.User is SocketGuildUser user)
            {
                if (WubbysFunHouse.IsDiscordStaff(user))
                {
                    return(Task.FromResult(PreconditionResult.FromSuccess()));
                }

                return(Task.FromResult(PreconditionResult.FromError($"{user.Mention} this is a Discord staff only command.")));
            }

            return(Task.FromResult(PreconditionResult.FromError($"{context.User.Mention} you must be in a guild to run this command.")));
        }
Example #4
0
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            if (context.User is SocketGuildUser user)
            {
                if (WubbysFunHouse.IsDiscordStaff(user))
                {
                    return(Task.FromResult(PreconditionResult.FromSuccess()));
                }

                DateTimeOffset?offset = DatabaseManager.Cooldowns.Check(context.Guild.Id, context.User.Id, command.Name, _PerUser);

                if (offset.HasValue)
                {
                    if (offset.Value.AddSeconds(_Seconds) >= DateTimeOffset.UtcNow)
                    {
                        string remaining = (offset.Value.AddSeconds(_Seconds) - DateTimeOffset.UtcNow).TotalSeconds.Seconds().Humanize();

                        if (_PerUser)
                        {
                            return(Task.FromResult(PreconditionResult.FromError($"{context.User.Mention} You need to wait {remaining} before you can use `{command.Name}` again. Cooldown is per-user.")));
                        }
                        else
                        {
                            return(Task.FromResult(PreconditionResult.FromError($"You need to wait {remaining} before you can use `{command.Name}` again. Cooldown is server wide.")));
                        }
                    }
                    else
                    {
                        LoggingManager.Log.Debug($"Command \"{command.Name}\" {(_PerUser ? "per-user" : "server wide")} cooldown finished {(_PerUser ? $"for {context.User}" : "")}in {context.Guild.Name}");

                        DatabaseManager.Cooldowns.Delete(context.Guild.Id, context.User.Id, command.Name, _PerUser);
                        return(Task.FromResult(PreconditionResult.FromSuccess()));
                    }
                }
                else
                {
                    LoggingManager.Log.Debug($"Command \"{command.Name}\" ({_Seconds}sec) {(_PerUser ? "per-user" : "server wide")} cooldown started {(_PerUser ? $"for {context.User}" : "")}in {context.Guild.Name}");

                    DatabaseManager.Cooldowns.Insert(context.Guild.Id, context.User.Id, command.Name);
                    return(Task.FromResult(PreconditionResult.FromSuccess()));
                }
            }
            else
            {
                return(Task.FromResult(PreconditionResult.FromError($"`{command.Name}` has a cooldown and can only be used on a server, not via direct messages.")));
            }
        }
Example #5
0
        public async Task UserInfo(SocketGuildUser user = null)
        {
            if (user == null)
            {
                return;
            }

            if (WubbysFunHouse.IsDiscordStaff(Context.User))
            {
                await Task.Delay(4500);

                bool mee6Responded = await Context.Channel.GetMessagesAsync(Context.Message, Direction.After).Flatten()
                                     .Where(x => x.Author.Id == 159985870458322944) // MEE6
                                     .Where(x => x.Embeds.Any(e => e.Fields.Any(f => f.Value.Contains(user.Id.ToString()))))
                                     .CountAsync() > 0;

                if (!mee6Responded)
                {
                    EmbedBuilder builder = new EmbedBuilder()
                    {
                        Color        = new Color(Constants.GeneralColor.R, Constants.GeneralColor.G, Constants.GeneralColor.B),
                        ThumbnailUrl = user.GetAvatarUrl(size: 1024)
                    };

                    builder.AddField($"Failover userinfo command for {user}", $"UserID | {user.Id}");

                    builder.AddField("Main role", $"{user.Roles.OrderByDescending(x => x.Position).First().Name}");

                    builder.AddField("Account created", $"{user.CreatedAt.ToString(Constants.DateTimeFormatMedium)}{Environment.NewLine}_{user.CreatedAt.Humanize()}_", true);

                    if (user.JoinedAt.HasValue)
                    {
                        builder.AddField("Joined server", $"{user.JoinedAt.Value.ToString(Constants.DateTimeFormatMedium)}{Environment.NewLine}_{user.JoinedAt.Value.Humanize()}_", true);
                    }

                    builder.Footer = new EmbedFooterBuilder()
                    {
                        Text = $"Requested by {Context.User} | {Context.User.Id}"
                    };

                    await BetterReplyAsync("MEE6 failed to fulfill request.", builder.Build(), parameters : $"{user} ({user.Id})");
                }
            }
        }
Example #6
0
        public async Task BlacklistAdd(SocketUser user = null)
        {
            if (user == null)
            {
                await BetterReplyAsync("You must mention a user to add them to the blacklist.", parameters : "user null");

                return;
            }

            if (WubbysFunHouse.IsDiscordStaff(user))
            {
                await BetterReplyAsync("You can not blacklist a discord staff member.", parameters : "user null");

                return;
            }

            if (SettingsManager.Configuration.DiscordBlacklist.Any(x => x.Key == Context.Guild.Id && x.Value.Contains(user.Id)))
            {
                await BetterReplyAsync($"{BetterUserFormat(user)} is already blacklisted.", parameters : $"{user} ({user.Id})");
            }
            else
            {
                if (SettingsManager.Configuration.DiscordBlacklist.ContainsKey(Context.Guild.Id))
                {
                    SettingsManager.Configuration.DiscordBlacklist[Context.Guild.Id].Add(user.Id);
                }
                else
                {
                    SettingsManager.Configuration.DiscordBlacklist.Add(Context.Guild.Id, new HashSet <ulong>()
                    {
                        user.Id
                    });
                }

                SettingsManager.Save();
                LoggingManager.Log.Info($"{user} ({user.Id}) was added to the blacklist by {Context.User} ({Context.User.Id})");

                await BetterReplyAsync($"{BetterUserFormat(user)} was added to the blacklist.", parameters : $"{user} ({user.Id})");
                await LogMessageEmbedAsync($"User blacklisted from using {Constants.ApplicationName}", user : user);
            }
        }
Example #7
0
        public async Task Warn(SocketUser user = null, [Remainder] string reason = "")
        {
            if (user == null)
            {
                return;
            }

            if (WubbysFunHouse.IsDiscordStaff(Context.User))
            {
                if (Context.Channel is SocketTextChannel channel)
                {
                    IAsyncEnumerable <IMessage> messages      = channel.GetMessagesAsync(200).Flatten();
                    IEnumerable <IMessage>      foundMessages = messages.Where(x => x.Author.Id == user.Id).OrderByDescending(x => x.CreatedAt).Take(10).ToEnumerable().OrderBy(x => x.CreatedAt);

                    StringBuilder builder = new StringBuilder();
                    foreach (IMessage message in foundMessages)
                    {
                        string header = "";
                        if (message.Attachments.Count > 0)
                        {
                            header = "<There is a file attachment with this message> ";
                        }

                        string content = "";
                        if (!string.IsNullOrWhiteSpace(message.Content))
                        {
                            content = message.Content;

                            List <MessageTag> tags = content.ParseDiscordMessageTags();

                            foreach (MessageTag tag in tags.Where(x => x.TagType == TagType.Channel))
                            {
                                if (Context.Guild.GetChannel(tag.Id) is SocketGuildChannel tagChannel)
                                {
                                    content = content.Replace(tag.ToString(), $"#{channel.Name}");
                                }
                            }

                            foreach (MessageTag tag in tags.Where(x => x.TagType == TagType.User))
                            {
                                if (UserFromUserId(tag.Id) is SocketGuildUser tagUser)
                                {
                                    content = content.Replace(tag.ToString(), $"@{BetterUserFormat(tagUser, true)} ({tag.Id})");
                                }
                            }

                            foreach (MessageTag tag in tags.Where(x => x.TagType == TagType.Role))
                            {
                                if (Context.Guild.GetRole(tag.Id) is SocketRole tagRole)
                                {
                                    content = content.Replace(tag.ToString(), $"@{tagRole.Name}");
                                }
                            }
                        }

                        builder.AppendLine($"{message.CreatedAt.ToString(Constants.DateTimeFormatMedium).ToLower()} utc: {header}{content}");
                    }

                    await Task.Delay(2000);

                    await LogMessageAsync($"● Recent messages from {BetterUserFormat(user)}", builder.ToString());
                }
                else
                {
                    await BetterReplyAsync($"Failed to retrieve context around the warn for {BetterUserFormat(user)}.", parameters : $"{user} ({user.Id}); {reason}");
                }
            }
        }