Esempio n. 1
0
        /// <inheritdoc />
        protected override Task <bool> SendReminder(ReminderData reminder)
        {
            if (this.ircClients.ContainsKey(reminder.Server))
            {
                string msg = string.Format("{0}: {1} ({2} ago) {3}", reminder.Nick, reminder.Reason, reminder.Duration, reminder.RequestedBy);
                this.ircClients[reminder.Server]?.Command("PRIVMSG", reminder.Channel, msg);

                return(Task.FromResult(true));
            }

            return(Task.FromResult(false));
        }
Esempio n. 2
0
        /// <inheritdoc />
        protected override Task <bool> SendReminder(ReminderData reminder)
        {
            if (this.ircClients.ContainsKey(reminder.Server))
            {
                string msg = string.Format("{0}: {1} ({2} ago) {3}", reminder.Nick, reminder.Reason, reminder.Duration, reminder.RequestedBy);
                this.ircClients[reminder.Server]?.Command("PRIVMSG", reminder.Channel, msg);

                var props = new Dictionary <string, string> {
                    { "server", reminder.Server.ToLowerInvariant() },
                    { "channel", reminder.Channel.ToLowerInvariant() },
                };
                this.TrackEvent("messageSent", props);

                return(Task.FromResult(true));
            }

            return(Task.FromResult(false));
        }
Esempio n. 3
0
 /// <summary>
 /// Attempts to process and send a reminder.
 /// </summary>
 /// <param name="notification">The reminder data.</param>
 /// <returns>True, if reminder was successfully processed.</returns>
 protected abstract Task <bool> SendReminder(ReminderData reminder);
Esempio n. 4
0
        /// <inheritdoc />
        protected override async Task <bool> SendReminder(ReminderData reminder)
        {
            var    channel = this.Client.GetChannel(Convert.ToUInt64(reminder.Channel)) as IMessageChannel;
            IGuild guild   = reminder.Server == "private" ? null : this.Client.GetGuild(Convert.ToUInt64(reminder.Server));

            // it may have been a PM so try to get the user
            var user = this.Client.GetUser(Convert.ToUInt64(reminder.UserId));

            if (channel == null && user != null && reminder.Server == "private")
            {
                channel = await user.GetOrCreateDMChannelAsync() as IDMChannel;
            }

            // if neither guild nor user was found, it belongs to another shard.
            if (guild == null && channel == null)
            {
                return(false);
            }

            string nick = reminder.Nick;

            if ((channel as ITextChannel)?.GetCurrentUserPermissions().SendMessages ?? false)
            {
                // try to find an exact match for the user, failing that perform a nick search
                if (string.IsNullOrEmpty(reminder.Requestor) && user != null)
                {
                    nick = user.Mention;
                }
                else
                {
                    nick = (await guild.GetUsersAsync().ConfigureAwait(false)).Find(nick).FirstOrDefault()?.Mention ?? nick;
                }
            }
            else if (guild != null)
            {
                // channel doesn't exist / missing permissions; so PM them instead.
                try
                {
                    channel = await user.GetOrCreateDMChannelAsync();
                }
                catch (Exception)
                {
                    // Failed to create DM channel.
                }
            }

            if (channel != null)
            {
                string msg = string.Format("{0}: {1} ({2} ago) {3}", nick, reminder.Reason, reminder.Duration, reminder.RequestedBy);
                try
                {
                    await channel.SendMessageAsync(msg);
                }
                catch (Exception ex)
                {
                    // TODO: retries
                    this.Logger.Log(LogType.Error, $"Failed to send reminder: {ex}");
                }
            }

            return(true);
        }