Esempio n. 1
0
        public async Task SetAway([Remainder] string input)
        {
            try
            {
                StringBuilder sb              = new StringBuilder();
                var           message         = input;
                var           user            = Context.User;
                string        userName        = string.Empty;
                string        userMentionName = string.Empty;
                if (user != null)
                {
                    userName        = user.Username;
                    userMentionName = user.Mention;
                }
                var data    = new AwayData();
                var away    = new AwaySystem();
                var attempt = data.getAwayUser(userName);

                if (string.IsNullOrEmpty(message.ToString()))
                {
                    message = "No message set!";
                }
                if (attempt != null)
                {
                    away.UserName = attempt.UserName;
                    away.Status   = attempt.Status;
                    if ((bool)away.Status)
                    {
                        sb.AppendLine($"You're already away, **{userMentionName}**!");
                    }
                    else
                    {
                        sb.AppendLine($"Marking you as away, **{userMentionName}**, with the message: *{message.ToString()}*");
                        away.Status   = true;
                        away.Message  = message;
                        away.UserName = userName;
                        away.TimeAway = DateTime.Now;

                        var awayData = new AwayData();
                        awayData.setAwayUser(away);
                    }
                }
                else
                {
                    sb.AppendLine($"Marking you as away, **{userMentionName}**, with the message: *{message.ToString()}*");
                    away.Status   = true;
                    away.Message  = message;
                    away.UserName = userName;
                    away.TimeAway = DateTime.Now;

                    var awayData = new AwayData();
                    awayData.setAwayUser(away);
                }
                await _cc.Reply(Context, sb.ToString());
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Something went wrong setting you away :(");
                _logger.LogError($"Away command error {ex.Message}");
                await _cc.Reply(Context, sb.ToString());
            }
        }
Esempio n. 2
0
        public async Task SetBack(bool forced = false, IGuildUser forceUser = null)
        {
            try
            {
                IGuildUser    user = null;
                StringBuilder sb   = new StringBuilder();
                var           data = new AwayData();
                if (forced)
                {
                    user = forceUser;
                }
                else
                {
                    user = Context.User as IGuildUser;
                }

                string userName        = string.Empty;
                string userMentionName = string.Empty;
                if (user != null)
                {
                    userName        = user.Username;
                    userMentionName = user.Mention;
                }
                var attempt = data.getAwayUser(userName);
                var away    = new AwaySystem();

                if (attempt != null)
                {
                    away.UserName = attempt.UserName;
                    away.Status   = attempt.Status;
                    if (!(bool)away.Status)
                    {
                        sb.AppendLine($"You're not even away yet, **{userMentionName}**");
                    }
                    else
                    {
                        away.Status  = false;
                        away.Message = string.Empty;
                        var awayData = new AwayData();
                        awayData.setAwayUser(away);
                        string awayDuration = string.Empty;
                        if (attempt.TimeAway.HasValue)
                        {
                            var awayTime = DateTime.Now - attempt.TimeAway;
                            if (awayTime.HasValue)
                            {
                                awayDuration = $"**{awayTime.Value.Days}** days, **{awayTime.Value.Hours}** hours, **{awayTime.Value.Minutes}** minutes, and **{awayTime.Value.Seconds}** seconds";
                            }
                        }
                        if (forced)
                        {
                            sb.AppendLine($"You're now set as back **{userMentionName}** (forced by: **{Context.User.Username}**)!");
                        }
                        else
                        {
                            sb.AppendLine($"You're now set as back, **{userMentionName}**!");
                        }
                        sb.AppendLine($"You were away for: [{awayDuration}]");
                    }
                    await _cc.Reply(Context, sb.ToString());
                }
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Something went wrong marking you as back :(");
                _logger.LogError($"Back command error {ex.Message}");
                await _cc.Reply(Context, sb.ToString());
            }
        }