示例#1
0
        public async Task WarnAsync(SocketGuildUser target, [Remainder] string reason)
        {
            var user      = Context.User as SocketGuildUser;
            var staffRole = user.Roles.FirstOrDefault(x => x.Name == "Staff");

            if (staffRole != null)
            {
                var recs = MongoCRUD.Instance.LoadAllRecordsById <UserWarnModel> (target.Id.ToString(), "Warnings", "_id");

                if (recs.Count != 0)
                {
                    ModeratorModel moderator = new ModeratorModel {
                        Username      = Context.User.Username,
                        Discriminator = Context.User.DiscriminatorValue,
                        id            = Context.User.Id
                    };
                    foreach (var rec in recs)
                    {
                        rec.warnings.Add(
                            new WarningModel {
                            warnReason = reason,
                            dateTime   = DateTime.Now.ToString("F"),
                            moderator  = moderator
                        });
                        MongoCRUD.Instance.UpdateWarning <UserWarnModel> ("Warnings", rec.userId, rec);
                    }
                }
                else
                {
                    ModeratorModel moderator = new ModeratorModel {
                        Username      = Context.User.Username,
                        Discriminator = Context.User.DiscriminatorValue,
                        id            = Context.User.Id
                    };
                    List <WarningModel> warningModel = new List <WarningModel> {
                        new WarningModel {
                            warnReason = reason,
                            dateTime   = DateTime.Now.ToString("F"),
                            moderator  = moderator
                        }
                    };
                    UserWarnModel userWarnModel = new UserWarnModel {
                        userId   = target.Id.ToString(),
                        warnings = warningModel
                    };
                    MongoCRUD.Instance.InsertRecord("Warnings", userWarnModel);
                }
                EmbedBuilder builder1 = new EmbedBuilder();
                builder1.WithTitle($"**You have been warned in the OEA**").WithDescription($"Reason: {reason}").WithColor(Discord.Color.Red)
                .WithFooter("If you think this was an error, please contact a moderator.");

                await target.SendMessageAsync("", false, builder1.Build());

                EmbedBuilder builder = new EmbedBuilder();
                builder.WithTitle($"**{target.Username}#{target.Discriminator} has been warned.**").WithDescription($"Reason: {reason}").WithColor(Discord.Color.Red);
                await ReplyAsync("", false, builder.Build());
            }
            else
            {
                await ReplyAsync("You do not have permission to use this command.");
            }
        }
示例#2
0
        public async Task MuteAsync(SocketGuildUser targetFake, string time, [Remainder] string reason)
        {
            var user      = Context.User as SocketGuildUser;
            var staffRole = user.Roles.FirstOrDefault(x => x.Name == "Staff");

            if (staffRole != null)
            {
                if (DiscordBot.Instance.currentServer != null)
                {
                    ModeratorModel moderator = new ModeratorModel {
                        Username      = Context.User.Username,
                        Discriminator = Context.User.DiscriminatorValue,
                        id            = Context.User.Id
                    };
                    TargetModel target = new TargetModel {
                        Username      = targetFake.Username,
                        Discriminator = targetFake.DiscriminatorValue,
                        id            = targetFake.Id
                    };
                    MuteModel muteModel = new MuteModel {
                        timeMuted = System.DateTime.Now,
                        isMuted   = true,
                        reason    = reason,
                        moderator = moderator,
                        target    = target
                    };
                    #region Adding time shit
                    if (time.Contains("d"))
                    {
                        var realTime = time.Substring(0, time.Length - 1);
                        muteModel.duration = time;

                        System.TimeSpan duration = new System.TimeSpan(int.Parse(realTime), 0, 0, 0);
                        DateTime        endMute  = System.DateTime.Now.Add(duration);
                        muteModel.muteFinished = endMute;
                    }
                    else if (time.Contains("h"))
                    {
                        var realTime = time.Substring(0, time.Length - 1);
                        muteModel.duration = time;

                        System.TimeSpan duration = new System.TimeSpan(0, int.Parse(realTime), 0, 0);
                        DateTime        endMute  = System.DateTime.Now.Add(duration);
                        muteModel.muteFinished = endMute;
                    }
                    else if (time.Contains("m"))
                    {
                        var realTime = time.Substring(0, time.Length - 1);
                        muteModel.duration = time;

                        System.TimeSpan duration = new System.TimeSpan(0, 0, int.Parse(realTime), 0);
                        DateTime        endMute  = System.DateTime.Now.Add(duration);
                        muteModel.muteFinished = endMute;
                    }
                    #endregion
                    MongoCRUD.Instance.InsertRecord("Mutes", muteModel);

                    var muteRole = Context.Guild.Roles.FirstOrDefault(r => r.Name == "Muted");

                    await targetFake.AddRoleAsync(muteRole);

                    EmbedBuilder builder = new EmbedBuilder();
                    builder.WithTitle($"**You have been muted in the OEA**").WithDescription($"Duration: {time}\nReason: {reason}").WithColor(Discord.Color.Red)
                    .WithFooter("If you think this was an error, please contact a moderator.");
                    await targetFake.SendMessageAsync("", false, builder.Build());

                    await ReplyAsync($"<@{targetFake.Id}> was muted by <@{Context.User.Id}>.\n" +
                                     $"Duration: {time}\n" +
                                     $"Reason: {reason}");
                }
                else
                {
                    await ReplyAsync("Please run the setup command before using this command.");
                }
            }
            else
            {
                await ReplyAsync("You do not have permission to use this command.");
            }
        }