Example #1
0
        public async Task away([Remainder] string message)
        {
            var sb = new StringBuilder();

            try
            {
                var data    = new awaydata();
                var away    = new Away();
                var attempt = data.getAwayUser(Context.User.Username);
                if (!string.IsNullOrEmpty(attempt.User))
                {
                    away.Status  = attempt.Status;
                    away.Message = attempt.Message;
                    away.User    = attempt.User;
                }
                else
                {
                    away.User = Context.User.Username;
                }

                if (string.IsNullOrEmpty(message.ToString()))
                {
                    message = "No message set!";
                }
                if (Context.User.Username == away.User)
                {
                    if (away.Status)
                    {
                        sb.AppendLine($"You're already away, **{Context.User.Mention}**!");
                    }
                    else
                    {
                        sb.AppendLine($"Marking you as away, {Context.User.Mention}, with the message: {message.ToString()}");
                        away.ToggleAway();
                        away.SetMessage(message.ToString());
                        away.User = Context.User.Username;
                        var awayData = new awaydata();
                        awayData.setAwayUser(away);
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine($"Away command error {ex.Message}");
                sb.AppendLine($"Sorry {Context.User.Mention}, something went wrong with the away command :(");
            }
            finally
            {
                await Context.Channel.SendMessageAsync(sb.ToString());
            }
        }
Example #2
0
        public async Task back()
        {
            var sb = new StringBuilder();

            try
            {
                var data    = new awaydata();
                var attempt = data.getAwayUser(Context.User.Username);
                var away    = new Away();
                if (!string.IsNullOrEmpty(attempt.User))
                {
                    away.Status  = attempt.Status;
                    away.Message = attempt.Message;
                    away.User    = attempt.User;
                }
                else
                {
                    away.User = Context.User.Username;
                }
                if (Context.User.Username == away.User)
                {
                    if (away.Status)
                    {
                        sb.AppendLine($"you're now set as back{Context.User.Mention}");
                        away.ToggleAway();
                        away.SetMessage(string.Empty);
                        var awaydata = new awaydata();
                        awaydata.setAwayUser(away);
                    }
                    else
                    {
                        sb.AppendLine($"you are not even away yet {Context.User.Mention}");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"away commannd error {ex.Message}");
                sb.AppendLine($"sorry {Context.User.Mention} something went wrong with back command");
            }
            finally
            {
                await Context.Channel.SendMessageAsync(sb.ToString());
            }
        }
Example #3
0
        public static async Task Message(SocketMessage message)
        {
            if (!message.Author.IsBot)
            {
                var userMentioned = message.MentionedUsers.FirstOrDefault();
                if (userMentioned != null)
                {
                    var awayData = new awaydata();
                    var awayUser = awayData.getAwayUser(userMentioned.Username);
                    if (awayUser != null)
                    {
                        string awayDuration = string.Empty;
                        if (awayUser.AwayTime.HasValue)
                        {
                            var awayTime = DateTime.Now - awayUser.AwayTime;
                            if (awayTime.HasValue)
                            {
                                awayDuration = $"**{awayTime.Value.Hours}** hours, **{awayTime.Value.Minutes}** minutes, and **{awayTime.Value.Seconds}** seconds";
                            }
                        }

                        Console.WriteLine($"Mentioned user {userMentioned.Username} -> {awayUser.User} -> {awayUser.Status}");
                        if ((bool)awayUser.Status)
                        {
                            if (userMentioned.Username == (awayUser.User))
                            {
                                var embeds = new EmbedBuilder
                                {
                                    Color        = new Color(199, 21, 112),
                                    ThumbnailUrl = userMentioned.GetAvatarUrl(),
                                    Title        = $" {awayUser.User} is away",
                                    Description  =
                                        $"{awayUser.User} is away since **{awayUser.AwayTime} for {awayDuration}** \n \n he/she left a **__Message__**: \n \n {awayUser.Message} \n \n \n refrain from pinging him/her unnecessarily"
                                };
                                await message.Channel.SendMessageAsync("", false, embeds);
                            }
                        }
                    }
                }
            }
        }