Пример #1
0
 public static PriorityState GetPriorityState(this PriorityTable pt)
 {
     if (pt.CheckValidity())
     {
         return(pt.State);
     }
     else
     {
         return(PriorityState.Normal);
     }
 }
Пример #2
0
        public Task PriorityUpdate(string id = "", string extendFormat = "", [Remainder] string customText = null)
        {
            return(Task.Run(async() =>
            {
                PriorityTable priority = Context.Repo.Priority.UpdatePriority(id, extendFormat, customText);
                if (priority != null)
                {
                    IGuildUser usr = null;
                    IGuild gld = null;
                    string namefor = "";
                    if (priority.State == PriorityState.User)
                    {
                        usr = Context.DiscordRestApi.GetGuildUserAsync(this.Context.Guild.Id, priority.GetUlongId()).Result;
                        namefor = $"{usr?.Username}#{usr?.Discriminator}";
                    }
                    else if (priority.State == PriorityState.Guild)
                    {
                        gld = Context.DiscordRestApi.GetApi.GetGuildAsync(priority.GetUlongId()).Result;
                        usr = gld?.GetOwnerAsync().Result;
                        namefor = $"{gld?.Name}";
                    }
                    else
                    {
                        throw new Exception("undefined PriorityState for PriorityManager");
                    }
                    if (priority.CheckValidity())
                    {
                        DateTime dtx = new DateTime();
                        dtx = dtx.Add(priority.Remining);
                        EmbedBuilder embed = new EmbedBuilder()
                        {
                            Author = new EmbedAuthorBuilder()
                            {
                                IconUrl = Context.Guild.CurrentUser.GetAvatarUrl(),
                                Name = Context.Guild.CurrentUser.Username
                            },
                            Color = Color.Green,
                            Title = "DISCORD PLAN IS UPDATED",
                        };
                        embed.Description += $"Type: **{priority.State}**\n" +
                                             $"Name: {namefor}\n" +
                                             $"Expires In: **{dtx.Year - 1}**Years **{dtx.Month - 1}**Months **{dtx.Day - 1}**days **{dtx.Hour}**hours\n";
                        embed.Description += "\n\n";
                        string text = $"[id:**{priority.Id}**][**{namefor}**].";
                        Log.Information("Priority: subs state is updated via cmd for {CustomerPriorityId} name with {CustomerName}, value {AddedValue} and Text {CustomText}", priority.Id, namefor, extendFormat, customText);
                        try
                        {
                            var dm = await usr.GetOrCreateDMChannelAsync();
                            var msg = await dm.SendMessageAsync(string.Empty, false, embed.Build(), Core.Utils.RequestOption);
                            await dm.CloseAsync(Core.Utils.RequestOption);
                        }

                        catch (Exception e)

                        {
                            await ReplyEmbedAsync($"{text} but DM was close, **COULDN'T** informed.", "DISCORD PLAN IS UPDATED");
                            return;
                        }
                        await ReplyEmbedAsync(text, "DISCORD PLAN IS UPDATED");
                    }
                    else
                    {
                        await ReplyEmbedAsync($"[id:{priority.Id}][{namefor}]. but was **expired**", "DISCORD PLAN IS UPDATED");
                    }
                }
                else
                {
                    await ReplyEmbedErrorAsync("format is not correct i.e.:\n **u193749607107395585** **1M** **1d** **1h** **Text**/**null(off)**(not required)");
                }
            }));
        }