Exemplo n.º 1
0
        protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            var deferral = args.TaskInstance.GetDeferral();

            switch (args.TaskInstance.Task.Name)
            {
            case TOAST_BACKGROUND_TASK_NAME:
                if (args.TaskInstance.TriggerDetails is ToastNotificationActionTriggerDetail details && TryGetToken(out var token))
                {
                    var arguments = ParseArgs(details.Argument);
                    var userInput = details.UserInput;

                    if (arguments.TryGetValue("channelId", out var cId) && ulong.TryParse(cId, out var channelId))
                    {
                        if (userInput.TryGetValue("tbReply", out var t) && t is string text)
                        {
                            var client = new DiscordRestClient(new DiscordConfiguration()
                            {
                                Token = token, TokenType = TokenType.User
                            });
                            await client.CreateMessageAsync(channelId, text, false, null, Enumerable.Empty <IMention>(), null);
                        }
                    }
                }
                break;
            }

            deferral.Complete();
        }