コード例 #1
0
        public async Task End()
        {
            var col = Database.GetCollection <Encounter>("Encounters");

            if (!col.Exists(x => x.Channel == Context.Channel.Id))
            {
                Encounter E = new Encounter()
                {
                    Channel = Context.Channel.Id
                };
                col.Insert(E);
            }

            var Encounter = col.FindOne(x => x.Channel == Context.Channel.Id);

            var request = new ConfirmationBuilder()
                          .WithContent(new PageBuilder().WithText("Are you sure you want to end the current encounter?"));

            var result = await Interactivity.SendConfirmationAsync(request.Build(), Context.Channel, TimeSpan.FromMinutes(1));

            if (result.Value)
            {
                Encounter.End();
                col.Update(Encounter);
                await ReplyAsync("Encounter ended!");
            }
            else
            {
                await ReplyAsync("Encounter resumed.");
            }
        }
コード例 #2
0
        public async Task TempMuteUser([RequireHierarchy] UserRef userRef, TimeSpan time, [Remainder] string reason)
        {
            if (time.TotalMinutes < 1)
            {
                await ReplyAsync("Can't temp-mute for less than a minute");

                return;
            }
            ModerationSettings settings = Context.Guild.LoadFromFile <ModerationSettings>();

            if (!(Context.Message.Author as IGuildUser).HasAdmin())
            {
                if (settings?.maxTempAction != null && time > settings.maxTempAction)
                {
                    await ReplyAsync("You are not allowed to punish for that long");

                    return;
                }
            }
            if (settings == null || settings.mutedRole == 0 || Context.Guild.GetRole(settings.mutedRole) == null)
            {
                await ReplyAsync("Muted role is null or invalid");

                return;
            }
            TempActionList actions = Context.Guild.LoadFromFile <TempActionList>(true);
            TempAct        oldAct  = actions.tempMutes.FirstOrDefault(tempMute => tempMute.User == userRef.ID);

            if (oldAct != null)
            {
                if (!(Context.Message.Author as IGuildUser).HasAdmin() && (oldAct.Length - (DateTime.UtcNow - oldAct.DateBanned)) >= time)
                {
                    await ReplyAsync($"{Context.User.Mention} please contact your admin(s) in order to shorten length of a punishment");

                    return;
                }
                string text    = $"{userRef.Name()} is already temp-muted for {oldAct.Length.LimitedHumanize()} ({(oldAct.Length - (DateTime.UtcNow - oldAct.DateBanned)).LimitedHumanize()} left), are you sure you want to change the length?";
                var    request = new ConfirmationBuilder()
                                 .WithContent(new PageBuilder().WithText(text))
                                 .Build();
                var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, TimeSpan.FromMinutes(2));

                if (result.Value)
                {
                    actions.tempMutes.Remove(oldAct);
                    actions.SaveToFile();
                }
                else
                {
                    await ReplyAsync("Command canceled");

                    return;
                }
            }

            await userRef.TempMute(time, reason, Context, settings, actions);

            Context.Message.DeleteOrRespond($"Temporarily muted {userRef.Mention()} for {time.LimitedHumanize(3)} because of {reason}", Context.Guild);
        }
コード例 #3
0
        public async Task ExecuteAsync(IGuildUser member, [Remainder] string reason = "Unspecified reason.")
        {
            var displayReason = reason.Length >= 75
                                ? Format.Code(reason.EscapeCodeblock().Truncate(150), "")
                                : Format.Code(Format.Sanitize(reason));

            var confirmationEmbed = CreateResponseEmbed(ResponseFormat.Default, "Confirmation",
                                                        $"Are you sure you want to softban {member.Mention} for {displayReason}?");

            var cancelledEmbed = CreateResponseEmbed(ResponseFormat.Cancelled, description:
                                                     "No action was taken.");

            var abortedEmbed = CreateResponseEmbed(ResponseFormat.Default, "Aborted",
                                                   "Interaction timed out.");

            var msg = await Context.AnswerAsync(embed : confirmationEmbed.Build());

            var request = new ConfirmationBuilder()
                          .WithContent(PageBuilder.FromEmbedBuilder(confirmationEmbed))
                          .WithCancelledEmbed(cancelledEmbed)
                          .WithTimeoutedEmbed(abortedEmbed)
                          .WithConfirmEmote(new Emoji("✅"))
                          .WithDeclineEmote(new Emoji("❌"))
                          .WithUsers((SocketUser)Context.User)
                          .WithDeletion(DeletionOptions.None)
                          .Build();

            var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, message : msg);

            if (result.IsSuccess)
            {
                try
                {
                    await member.BanAsync(reason : reason);

                    await Context.Guild.RemoveBanAsync(member);

                    var successEmbed = CreateResponseEmbed(ResponseFormat.Success, description:
                                                           $"Softbanned {member.Mention} for {displayReason}");

                    await msg.ModifyAsync(props => props.Embed = successEmbed.Build());
                }
                catch
                {
                    var errorEmbed = CreateResponseEmbed(ResponseFormat.Error, description:
                                                         $"Couldn't softban {member.Mention}. Check if I have enough permissions.");

                    await msg.ModifyAsync(props => props.Embed = errorEmbed.Build());
                }
            }
        }
コード例 #4
0
        public async Task Ban([RequireHierarchy] UserRef userRef, [Remainder] string reason)
        {
            if (reason.Split(' ').First().ToTime() != null)
            {
                var query   = "Are you sure you don't mean to use !tempban?";
                var request = new ConfirmationBuilder()
                              .WithContent(new PageBuilder().WithText(query))
                              .Build();
                var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, TimeSpan.FromMinutes(1));

                if (result.Value)
                {
                    await ReplyAsync("Command Canceled");

                    return;
                }
            }

            TempActionList actions = Context.Guild.LoadFromFile <TempActionList>(false);

            if (actions?.tempBans?.Any(tempBan => tempBan.User == userRef.ID) ?? false)
            {
                var query   = "User is already tempbanned, are you sure you want to ban?";
                var request = new ConfirmationBuilder()
                              .WithContent(new PageBuilder().WithText(query))
                              .Build();
                var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, TimeSpan.FromMinutes(2));

                if (result.Value)
                {
                    await ReplyAsync("Command Canceled");

                    return;
                }
                actions.tempBans.Remove(actions.tempBans.First(tempban => tempban.User == userRef.ID));
            }
            else if ((await Context.Guild.GetBansAsync()).Any(ban => ban.User.Id == userRef.ID))
            {
                await ReplyAsync("User has already been banned permanently");

                return;
            }
            userRef.User?.TryNotify($"You have been perm banned in the {Context.Guild.Name} discord for {reason}");
            await Context.Guild.AddBanAsync(userRef.ID, reason : reason);

            DiscordLogging.LogTempAct(Context.Guild, Context.Message.Author, userRef, "Bann", reason, Context.Message.GetJumpUrl(), TimeSpan.Zero);
            Context.Message.DeleteOrRespond($"{userRef.Name(true)} has been banned for {reason}", Context.Guild);
        }
コード例 #5
0
        public async Task ExampleConfirmationAsync()
        {
            var request = new ConfirmationBuilder()
                          .WithContent(new PageBuilder().WithText("Please Confirm"))
                          .Build();

            var result = await Interactivity.SendConfirmationAsync(request, Context.Channel);

            if (result.Value)
            {
                await Context.Channel.SendMessageAsync("Confirmed :thumbsup:!");
            }
            else
            {
                await Context.Channel.SendMessageAsync("Declined :thumbsup:!");
            }
        }
コード例 #6
0
        public async Task Delete([Remainder] string Name)
        {
            User User = Utils.GetUser(Context.User.Id);
            var  col  = Database.GetCollection <Actor>("Actors");

            var results = col.Find(x => x.Owner == Context.User.Id && (x.Name.StartsWith(Name.ToLower()) || x.Name2.StartsWith(Name.ToLower())));

            if (results.Count() == 0)
            {
                await ReplyAsync(Context.User.Mention + ", You have no characters who's Branded or Guardian's name starts with \"" + Name + "\".");

                return;
            }
            else
            {
                Actor actor = results.FirstOrDefault();

                var request = new ConfirmationBuilder()
                              .WithUsers(Context.User)
                              .WithContent(new PageBuilder().WithText("Are you sure you want to delete **" + actor.Name + "** and **" + actor.Name2 + "**?"))
                              .Build();

                var result = await Interactivity.SendConfirmationAsync(request, Context.Channel, TimeSpan.FromMinutes(1));

                if (result.Value)
                {
                    if (User.Active == actor)
                    {
                        User.Active = null;
                        Utils.UpdateUser(User);
                    }

                    col.Delete(actor.ID);
                    await ReplyAsync(Context.User.Mention + ", Deleted characters **" + actor.Name + "** and **" + actor.Name2 + "**.");
                }
                else
                {
                    await ReplyAsync(Context.User.Mention + ", Cancelled Deletion.");
                }
            }
        }