Пример #1
0
        public async Task <IUserMessage> SendPaginatedMessageAsync(OrikivoCommandContext Context, PaginatedMessage message, ICriteria <SocketReaction> criteria = null)
        {
            PaginatedMessageCallback caller = new PaginatedMessageCallback(this, Context, message, criteria);
            await caller.ShowAsync().ConfigureAwait(false);

            return(caller.Message);
        }
Пример #2
0
        public async Task <SocketMessage> ListenToReplyAsync(OrikivoCommandContext Context, ICriteria <SocketMessage> criteria, TimeSpan?timeout = null)
        {
            timeout = timeout ?? _timeout;
            TaskCompletionSource <SocketMessage> trigger = new TaskCompletionSource <SocketMessage>();


            async Task Listener(SocketMessage message)
            {
                bool ensured = await criteria.EnsureAsync(Context, message).ConfigureAwait(false);

                if (ensured)
                {
                    trigger.SetResult(message);
                }
            }

            Context.Client.MessageReceived += Listener;

            Task <SocketMessage> handler = trigger.Task;
            Task delay = Task.Delay(timeout.Value);
            Task task  = await Task.WhenAny(handler, delay).ConfigureAwait(false);

            Context.Client.MessageReceived -= Listener;

            if (task == handler)
            {
                return(await handler.ConfigureAwait(false));
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
 public PaginatedMessageCallback(DynamicManager manager, OrikivoCommandContext context, PaginatedMessage message, ICriteria <SocketReaction> criteria = null)
 {
     Manager   = manager;
     Context   = context;
     _criteria = criteria ?? new EmptyCriteria <SocketReaction>();
     _message  = message;
     pages     = _message.Pages.Count();
 }
Пример #4
0
        public async Task <IUserMessage> ClearReplyAsync(OrikivoCommandContext Context, string content, bool tts = false, Embed embed = null, TimeSpan?timeout = null, RequestOptions options = null)
        {
            timeout = timeout ?? _timeout;
            IUserMessage message = await Context.Channel.SendMessageAsync(content, tts, embed, options).ConfigureAwait(false);

            _ = Task.Delay(timeout.Value).ContinueWith(_ => message.DeleteAsync().ConfigureAwait(false)).ConfigureAwait(false);
            return(message);
        }
        public static async Task ReadOptionAsync(OrikivoCommandContext Context, int i)
        {
            if (!OptionsHelper.TryParseOption(i, out AccountOption ao))
            {
                await Context.Channel.ThrowAsync("Invalid context.", "The integer specified led to no results.");

                return;
            }
            await Context.Channel.ReadAsync(ao.Interpret(), Context.Account);
        }
        public static async Task SetOptionAsync(OrikivoCommandContext Context, AccountOption option, object obj)
        {
            AccountOptions opts = AccountOptions.Default;

            opts.TryGetValue(option, out object value);
            if (opts.TrySetValue(option, obj))
            {
                string msg = $"{option} - {(value.Exists() ? value.Read() : "Undefined")}";
                opts.TryGetValue(option, out value);
                msg += $" => {(value.Exists() ? value.Read() : "Undefined")}";
                await Context.Channel.SendMessageAsync(msg);
            }
        }
Пример #7
0
 public async Task GetCurrentPrefs(OrikivoCommandContext Context)
 {
     if (_safeQuota.ContainsKey(Context.Guild.Id))
     {
         _safeData safeData = new _safeData();
         _safeQuota.TryGetValue(Context.Guild.Id, out safeData);
         await Context.Channel.SendMessageAsync($"`current safe preference : {safeData.guildSafePref}\n [sayd state : {safeData.guildSayDToggle}`");
     }
     else
     {
         var returnMsg = "The guild pref file has not been set, and will default to true.\nUse [gpref safemode <t || f> or [gpref sayd <t || f> to set.";
         await Context.Channel.SendMessageAsync(returnMsg);
     }
 }
Пример #8
0
        public async Task <bool> EnsureAsync(OrikivoCommandContext Context, T parameter)
        {
            foreach (ICriteria <T> criteria in _criteria)
            {
                bool result = await criteria.EnsureAsync(Context, parameter).ConfigureAwait(false);

                if (!result)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #9
0
        private async Task InsultDefineLevel(OrikivoCommandContext Context, int insultLevel, bool hasUpdated)
        {
            _insultData insultData = new _insultData()
            {
                guildInsultLevel = insultLevel
            };
            _insultData ignore;

            _insultQuota.TryRemove(Context.Guild.Id, out ignore);
            _insultQuota.AddOrUpdate(Context.Guild.Id, insultData, ((key, oldValue) => insultData));
            var embedInsultCheck = new EmbedBuilder
            {
                Color       = new Color(0, 0, 0),
                Description = $"**Insult-o-Meter** ( { (hasUpdated == true ? $"Insult level set to {insultData.guildInsultLevel + 1} : {insultCurrentLevelNames[insultData.guildInsultLevel]}" : $"Insult level created and set to {insultData.guildInsultLevel + 1} : {insultCurrentLevelNames[insultData.guildInsultLevel]}") } )"
            };
Пример #10
0
        private async Task StatusCreate(OrikivoCommandContext Context, string statusTypeSelection, string expression, bool hasUpdated)
        {
            if (expression == null)
            {
                expression = "";
            }
            _statusData statusData = new _statusData {
                statusType = statusTypeSelection,
                expression = expression
            };
            _statusData ignore;

            _statusQuota.TryRemove(Context.User.Id, out ignore);
            _statusQuota.AddOrUpdate(Context.User.Id, statusData, ((key, oldValue) => statusData));
            await Context.Channel.SendMessageAsync($"{(hasUpdated == true ? $"`You updated your status to {statusData.statusType}.`" : $"`You are now set as {statusData.statusType}.`")}");
Пример #11
0
        public Task <SocketMessage> ListenToReplyAsync(OrikivoCommandContext Context, bool sourceUser = true, bool sourceChannel = true, TimeSpan?timeout = null)
        {
            Criteria <SocketMessage> criteria = new Criteria <SocketMessage>();

            if (sourceUser)
            {
                criteria.Add(new EnsureUserCriteria());
            }
            if (sourceChannel)
            {
                criteria.Add(new EnsureChannelCriteria());
            }

            return(ListenToReplyAsync(Context, criteria, timeout));
        }
Пример #12
0
        private async Task SafeDefineBool(OrikivoCommandContext Context, bool safeReturn, bool hasUpdated)
        {
            _safeData safeData = new _safeData()
            {
                guildSafePref   = safeReturn,
                guildSayDToggle = GetSayDPref(Context, Context.Guild),
            };
            _safeData ignore;

            _safeQuota.TryRemove(Context.Guild.Id, out ignore);
            _safeQuota.AddOrUpdate(Context.Guild.Id, safeData, ((key, oldValue) => safeData));
            var embedSafeCheck = new EmbedBuilder
            {
                Color       = new Color(0, 0, 0),
                Description = $"**Safe Check** ( { (hasUpdated == true ? $"Safe mode set to {safeData.guildSafePref}." : $"Guild preferences created and set to {safeData.guildSafePref}.") } )"
            };
Пример #13
0
        public static Embed Throw(OrikivoCommandContext ctx, string reason, string example = null, bool prefix = false)
        {
            EmbedBuilder e = new EmbedBuilder();

            e.WithColor(GetColor("error"));
            e.WithTitle(reason);
            if (example.Exists())
            {
                if (prefix)
                {
                    example = ctx.Server.Config.GetPrefix(ctx) + example;
                }

                e.WithDescription(example);
            }

            return(e.Build());
        }
Пример #14
0
        public static async Task DemoLetterAsync(OrikivoCommandContext Context, string subject, string message, string url = null)
        {
            if (url.Exists())
            {
                if (!url.IsProperUrl())
                {
                    url = null;
                }

                /*
                 * if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
                 * {
                 *  url = null;
                 * }
                 */
            }
            OldAccount       a  = Context.Account ?? Context.Data.GetOrAddAccount(Context.User);
            LetterAttachment la = null;

            if (Context.Message.Attachments.Funct())
            {
                la = new LetterAttachment(Context.Message.Attachments.First());
            }
            else if (url.Exists())
            {
                la = new LetterAttachment(url);
            }

            Letter test = new Letter(new Author(a), subject, message, la);

            //Letter test2 = new Letter(a, "hello2", "what is this", null);
            //test2 = test2.AppendThread(test);

            test.AddRecipient(Context.User.Id);
            test.AddRecipient(Context.Client.CurrentUser.Id);
            test.Relock();

            await Context.Channel.SendSourceAsync(test.Interpret().ToMessage(IconFormat.Portable));
        }
Пример #15
0
        public async Task ExecuteAsync(OrikivoCommandContext Context, int argPos)
        {
            IResult task = await _service.ExecuteAsync(Context, argPos, _provider, MultiMatchHandling.Exception);

            if (!task.IsSuccess)
            {
                if (task.Error.HasValue)
                {
                    if (task.Error == CommandError.UnknownCommand)
                    {
                        if (!Context.Server.Config.ThrowUnknown)
                        {
                            return;
                        }
                    }
                }

                if (Context.Server.Config.Throw)
                {
                    await Context.Channel.ThrowAsync(task.ErrorReason.MarkdownBold());
                }
            }
        }
Пример #16
0
 // flag a letter, and remove it from your mailbox.
 public static async Task ReportLetterAsync(OrikivoCommandContext Context, ulong id)
 {
     // Context.NewAccount.TryGetLetter(id, out Letter l);
     // l.FlagAsync(reason); - deletes the letter from the account, and places it into Global.Mail.Reports;
 }
Пример #17
0
 // builds and sends a draft to all specified users.
 public static async Task SendDraftAsync(OrikivoCommandContext Context, ulong id)
 {
     // Context.NewAccount.TryGetDraft(id, out Draft d);
 }
Пример #18
0
 // Builds a draft letter.
 public static async Task BuildDraftAsync(OrikivoCommandContext Context, ulong id)
 {
     // Context.NewAccount.ComposeDraft();
 }
Пример #19
0
 // build and send letter to a user.
 public static async Task ComposeLetterAsync(OrikivoCommandContext Context)
 {
     // Context.NewAccount.Send(u, );
 }
Пример #20
0
 public static async Task CheckStoresAsync(OrikivoCommandContext Context)
 {
     MessageBuilder mb = ShopSystem.CheckStores();
     await Context.Channel.SendSourceAsync(mb.Build());
 }
Пример #21
0
        public Task <bool> EnsureAsync(OrikivoCommandContext Context, IMessage message)
        {
            bool equals = Context.Channel.Id == message.Channel.Id;

            return(Task.FromResult(equals));
        }
Пример #22
0
 // block a specific user from mail interaction.
 public static async Task BlockContactAsync(OrikivoCommandContext Context, SocketUser u)
 {
     // Context.NewAccount.TryBlockContact(u);
 }
Пример #23
0
 public static async Task ReadOptionsAsync(OrikivoCommandContext Context)
 {
     await Context.Channel.SendEmbedAsync(OptionsHelper.InterpretAll().PeekAll(Context.Account));
 }
Пример #24
0
 // unblock a blocked user...
 public static async Task UnblockContactAsync(OrikivoCommandContext Context)
 {
     // Context.NewAccount.TryUnblockContact(u);
 }
Пример #25
0
 public static async Task ReadOptionAsync(OrikivoCommandContext Context, AccountOption option)
 {
     await Context.Channel.ReadAsync(option.Interpret(), Context.Account);
 }
Пример #26
0
        public Task <bool> EnsureAsync(OrikivoCommandContext Context, SocketReaction parameter)
        {
            bool result = parameter.UserId == Context.User.Id;

            return(Task.FromResult(result));
        }
Пример #27
0
 // throw away a letter.
 public static async Task TossLetterAsync(OrikivoCommandContext Context)
 {
     // Context.NewAccount.TryGetLetter(id, out Letter l);
     // l.Toss();
 }
Пример #28
0
 // pass an already existing letter to another user.
 public static async Task ForwardLetterAsync(OrikivoCommandContext Context, SocketUser u)
 {
     // Context.NewAccount.TryGetLetter(id, out Letter l);
     // l.Forward(u);
 }
Пример #29
0
 public Task <bool> EnsureAsync(OrikivoCommandContext Context, T parameter)
 => Task.FromResult(true);
Пример #30
0
 public CommandHelper(OrikivoCommandContext context, CommandService service)
 {
     Context = context;
     Service = service;
 }