Beispiel #1
0
 /// <summary>
 /// Creates a reminder.
 /// <see href="https://api.slack.com/methods/reminders.add" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `reminders:write`
 /// </param>
 /// <param name='text'>
 /// The content of the reminder
 /// </param>
 /// <param name='user'>
 /// The user who will receive the reminder. If no user is specified, the
 /// reminder will go to user who created it.
 /// </param>
 /// <param name='time'>
 /// When this reminder should happen: the Unix timestamp (up to five years from
 /// now), the number of seconds until the reminder (if within 24 hours), or a
 /// natural language description (Ex. "in 15 minutes," or "every Thursday")
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <AddOKResponseModelModelModel> AddAsync(this IReminders operations, string token = default(string), string text = default(string), string user = default(string), string time = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.AddWithHttpMessagesAsync(token, text, user, time, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Beispiel #2
0
        private static async Task <IReadOnlyList <IReminder> > GetReminders(IReminders reminders, [NotNull] ResolveFieldContext <object> context)
        {
            var userCtx = (GraphQLUserContext)context.UserContext;
            var user    = userCtx.ClaimsPrincipal;
            var client  = userCtx.DiscordClient;

            //If they are not a discord user, return an empty list
            var dUser = user.TryGetDiscordUser(client);

            if (dUser == null)
            {
                return(Array.Empty <IReminder>());
            }

            DateTime?before = null;

            if (context.Arguments.TryGetValue("before", out var beforeObj) && beforeObj is DateTime beforeTime)
            {
                before = beforeTime;
            }

            DateTime?after = null;

            if (context.Arguments.TryGetValue("after", out var afterObj) && afterObj is DateTime afterTime)
            {
                after = afterTime;
            }

            return(await reminders.Get(userId : dUser.Id, after : after, before : before).ToArray());
        }
Beispiel #3
0
 /// <summary>
 /// Lists all reminders created by or for a given user.
 /// <see href="https://api.slack.com/methods/reminders.list" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `reminders:read`
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ListOKResponseModelModelModelModel> ListAsync(this IReminders operations, string token = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.ListWithHttpMessagesAsync(token, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Gets information about a reminder.
 /// <see href="https://api.slack.com/methods/reminders.info" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `reminders:read`
 /// </param>
 /// <param name='reminder'>
 /// The ID of the reminder
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <InfoOKResponse> InfoAsync(this IReminders operations, string token = default(string), string reminder = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.InfoWithHttpMessagesAsync(token, reminder, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Beispiel #5
0
        public AsyncReminderSender(IReminders reminders, DiscordSocketClient client)
        {
            _reminders = reminders;
            _client    = client;

            _thread = Task.Run(ThreadEntry);
        }
Beispiel #6
0
        [ItemCanBeNull] private async Task <IReminder> CreateReminder(IReminders reminders, [NotNull] ResolveFieldContext <object> context)
        {
            var userCtx = (GraphQLUserContext)context.UserContext;
            var user    = userCtx.ClaimsPrincipal;
            var client  = userCtx.DiscordClient;

            //If they are not a discord user, return null
            var dUser = user.TryGetDiscordUser(client);

            if (dUser == null)
            {
                return(null);
            }

            //Get message or early exit
            if (!context.Arguments.TryGetValue("message", out var messageObj) || !(messageObj is string message))
            {
                return(null);
            }

            //Get trigger time or exit if none specified
            if (!context.Arguments.TryGetValue("trigger_time", out var triggerTime) || !(triggerTime is DateTime trigger))
            {
                return(null);
            }

            //Check if we're trying to schedule an event in the past
            if (trigger < DateTime.UtcNow)
            {
                return(null);
            }

            //Get channel or exit if none specified or user cannot write into this channel
            if (context.Arguments.TryGetValue("channel_id", out var channelIdStr) && ulong.TryParse(channelIdStr as string ?? "", out var channelId))
            {
                //Get the channel or exit if it doesn't exist
                var channel = client.GetChannel(channelId) as ITextChannel;
                if (channel == null)
                {
                    return(null);
                }

                //Check if user is in channel
                var gUser = await channel.GetUserAsync(dUser.Id);

                if (gUser == null)
                {
                    return(null);
                }

                //check user has permission to write in this channel
                var permission = gUser.GetPermissions(channel);
                if (!permission.Has(ChannelPermission.SendMessages))
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            var prelude = $"{dUser.Mention} Reminder from {DateTime.UtcNow.Humanize(dateToCompareAgainst: trigger, culture: CultureInfo.GetCultureInfo("en-gn"))}...";

            return(await reminders.Create(trigger, prelude, message, channelId, dUser.Id));
        }
Beispiel #7
0
 public AsyncReminderSender(IReminders reminders, DiscordSocketClient client)
 {
     _reminders = reminders;
     _client    = client;
 }
Beispiel #8
0
 public EventTimeoutAction(IReminder reminder, IReminders reminders, DiscordSocketClient client)
 {
     _reminder  = reminder;
     _reminders = reminders;
     _client    = client;
 }
Beispiel #9
0
 /// <summary>
 /// Marks a reminder as complete.
 /// <see href="https://api.slack.com/methods/reminders.complete" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `reminders:write`
 /// </param>
 /// <param name='reminder'>
 /// The ID of the reminder to be marked as complete
 /// </param>
 public static CompleteOKResponse Complete(this IReminders operations, string token = default(string), string reminder = default(string))
 {
     return(operations.CompleteAsync(token, reminder).GetAwaiter().GetResult());
 }
Beispiel #10
0
 /// <summary>
 /// Creates a reminder.
 /// <see href="https://api.slack.com/methods/reminders.add" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `reminders:write`
 /// </param>
 /// <param name='text'>
 /// The content of the reminder
 /// </param>
 /// <param name='user'>
 /// The user who will receive the reminder. If no user is specified, the
 /// reminder will go to user who created it.
 /// </param>
 /// <param name='time'>
 /// When this reminder should happen: the Unix timestamp (up to five years from
 /// now), the number of seconds until the reminder (if within 24 hours), or a
 /// natural language description (Ex. "in 15 minutes," or "every Thursday")
 /// </param>
 public static AddOKResponseModelModelModel Add(this IReminders operations, string token = default(string), string text = default(string), string user = default(string), string time = default(string))
 {
     return(operations.AddAsync(token, text, user, time).GetAwaiter().GetResult());
 }
Beispiel #11
0
 /// <summary>
 /// Lists all reminders created by or for a given user.
 /// <see href="https://api.slack.com/methods/reminders.list" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `reminders:read`
 /// </param>
 public static ListOKResponseModelModelModelModel List(this IReminders operations, string token = default(string))
 {
     return(operations.ListAsync(token).GetAwaiter().GetResult());
 }
Beispiel #12
0
 /// <summary>
 /// Gets information about a reminder.
 /// <see href="https://api.slack.com/methods/reminders.info" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='token'>
 /// Authentication token. Requires scope: `reminders:read`
 /// </param>
 /// <param name='reminder'>
 /// The ID of the reminder
 /// </param>
 public static InfoOKResponse Info(this IReminders operations, string token = default(string), string reminder = default(string))
 {
     return(operations.InfoAsync(token, reminder).GetAwaiter().GetResult());
 }
Beispiel #13
0
 public Reminders(IReminders reminders)
 {
     _reminders = reminders;
 }