Exemplo n.º 1
0
        private static async Task <ICommandResult> CreateReminder(DiscordUserMessageContext context, string user, string message, DateTimeOffset targetTime)
        {
            IUser targetUser;

            if (context.Message.MentionedUserIds.Count > 0)
            {
                targetUser = await context.Channel.GetUserAsync(context.Message.MentionedUserIds.First());
            }
            else if (context.Message.Tags.Count > 0 && context.Message.Tags.First().Type == TagType.UserMention && (targetUser = context.Bot.Client.GetUser(context.Message.Tags.First().Key)) != null)
            {
            }
            else
            {
                targetUser = (SocketUser)await CommandTools.GetUserByUsername(user, context.Channel);
            }

            if (targetUser == null)
            {
                return(new ErrorResult("User not found"));
            }

            context.Bot.Reminders.Reminders.Add(
                new ReminderInfo
            {
                Message    = message,
                ReceiverId = targetUser.Id,
                SenderId   = context.Message.Author.Id,
                Timestamp  = targetTime
            });

            context.Bot.Reminders.SaveConfig();

            return(new SuccessResult($"Reminder set for {TimeZoneInfo.ConvertTimeBySystemTimeZoneId(targetTime, context.Bot.DefaultTimeZone):f}"));
        }
Exemplo n.º 2
0
        public static async Task <ICommandResult> Status(ICommandContext context, [DisplayName("username | @ mention"), JoinRemainingParameters] string user)
        {
            IUser targetUser;

            switch (context)
            {
            case DiscordMessageContext discordContext:
                if (discordContext.Message.MentionedUserIds.Count > 0)
                {
                    targetUser = await discordContext.Channel.GetUserAsync(discordContext.Message.MentionedUserIds.First());
                }
                else if (discordContext.Message.Tags.Count > 0 && discordContext.Message.Tags.First().Type == TagType.UserMention && (targetUser = context.Bot.Client.GetUser(discordContext.Message.Tags.First().Key)) != null)
                {
                }
                else
                {
                    targetUser = (SocketUser)await CommandTools.GetUserByUsername(user, discordContext.Channel);
                }
                break;

            case DiscordChannelDescriptionContext channelDescription:
                targetUser = (SocketUser)await CommandTools.GetUserByUsername(user, (IMessageChannel)channelDescription.Channel);

                break;

            default:
                return(new ErrorResult($"The `status` command is not valid in the context `{context.GetType().Name}`"));
            }

            if (targetUser == null || context.Bot.Statuses.Statuses == null)
            {
                return(new ErrorResult("No status history data found"));
            }

            if (context.Bot.Statuses.Statuses.ContainsKey(targetUser.Id))
            {
                var statusInfo = context.Bot.Statuses.Statuses[targetUser.Id];

                Color?color;
                switch (targetUser.Status)
                {
                case UserStatus.Online:
                    color = new Color(76, 175, 80);
                    break;

                case UserStatus.Idle:
                case UserStatus.AFK:
                    color = new Color(255, 235, 59);
                    break;

                case UserStatus.DoNotDisturb:
                    color = new Color(244, 67, 54);
                    break;

                default:
                    color = null;
                    break;
                }

                EmbedBuilder statusEmbed = new EmbedBuilder
                {
                    Author = new EmbedAuthorBuilder
                    {
                        Name    = targetUser.NicknameOrUsername(),
                        IconUrl = targetUser.AvatarUrlOrDefaultAvatar()
                    },
                    Color       = color,
                    Description = targetUser.Status.ToString()
                };

                statusEmbed.AddField($"{targetUser.Status} For", (DateTimeOffset.Now - statusInfo.StatusLastChanged).ToLongString(), true);
                if (targetUser.Status != UserStatus.Online)
                {
                    statusEmbed.AddField("Last Online", $"{(DateTimeOffset.Now - statusInfo.LastOnline).ToLongString()} ago");
                }
                if (statusInfo.Game != null)
                {
                    statusEmbed.AddField($"In Game {statusInfo.Game}", (DateTimeOffset.Now - statusInfo.StartedPlaying)?.ToLongString() ?? "Unknown amount of time");
                }
                if (statusInfo.LastMessageSent != DateTimeOffset.MinValue)
                {
                    string text = (DateTimeOffset.Now - statusInfo.LastMessageSent).ToLongString();
                    statusEmbed.AddField("Last Message Sent", text.Length > 0 ? $"{text} ago" : "Just now");
                }

                return(new SuccessResult(embed: statusEmbed.Build()));
            }

            return(new ErrorResult("User status history not found"));
        }