예제 #1
0
        private async Task ProcessList()
        {
            try
            {
                IMessageChannel channel = await ChannelProvider.GetDMChannelAsync(this.Context);

                List <TReminder> reminders = this._reminderDAO.GetAll(this.Context.User.Id);
                IOrderedEnumerable <TReminder> orderedList = reminders.OrderBy(x => x.ExpirationTime);

                FormattedEmbedBuilder message = new FormattedEmbedBuilder()
                                                .AppendTitle($"{XayahReaction.Hourglass} Active reminders");
                if (orderedList.Count() > 0)
                {
                    foreach (TReminder entry in orderedList)
                    {
                        message.AddField($"Expires: {entry.ExpirationTime} UTC", entry.Message, inline: false);
                    }
                }
                else
                {
                    message.AppendDescription("imagine a soulrending void", AppendOption.Italic);
                }
                await channel.SendEmbedAsync(message);

                await this.Context.Message.AddReactionIfNotDMAsync(this.Context, XayahReaction.Envelope);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
예제 #2
0
 public static async Task <(IUserMessage Message, EmbedBuilder Embed)?> TrySendEmbedAsync(this IMessageChannel Channel,
                                                                                          object Description = null, object Title = null, object Footer = null, object ImageUrl = null, object ThumbnailUrl = null, object Url = null)
 {
     try
     {
         return(await Channel.SendEmbedAsync(Description, Title, Footer, ImageUrl, ThumbnailUrl, Url));
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #3
0
        private async void HandleExpiredReminder(object state)
        {
            TReminder reminder = state as TReminder;

            await this._reminderDAO.RemoveAsync(reminder);

            StopTimer(this.BuildTimerKey(reminder.UserId, reminder.ExpirationTime));

            IMessageChannel channel = await ChannelProvider.GetDMChannelAsync(this._client, reminder.UserId);

            FormattedEmbedBuilder message = new FormattedEmbedBuilder()
                                            .AppendTitle($"{XayahReaction.Clock} Reminder expired")
                                            .AppendDescription(reminder.Message);
            await channel.SendEmbedAsync(message);
        }
예제 #4
0
 /// <summary>
 /// Logs a specific string, as given in message, as an error.
 /// </summary>
 /// <param name="message">The message to log.</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 public static async Task LogError(string message)
 {
     PrintErrorWithTime(message);
     if (loggingFilePath != null)
     {
         await WriteLogWithTime(message, true);
     }
     if (message.Length > 2042)
     {
         message = message.Substring(0, 2039) + "...";
     }
     DiscordLogQueue.Enqueue(new Task(
                                 () =>
     {
         var embed = new EmbedBuilder
         {
             Title       = "Error",
             Color       = new Color(200, 0, 0),
             Description = $"```{message}```",
             Author      = new EmbedAuthorBuilder
             {
                 IconUrl = Shinoa.Client.CurrentUser.GetAvatarUrl(),
                 Name    = nameof(Shinoa),
             },
             Timestamp = DateTimeOffset.Now,
             Footer    = new EmbedFooterBuilder
             {
                 Text = Shinoa.VersionString,
             },
         };
         var sendMessageAsync = loggingChannel?.SendEmbedAsync(embed);
         if (sendMessageAsync == null)
         {
             return;
         }
         try
         {
             sendMessageAsync.GetAwaiter().GetResult();
         }
         catch (Exception e)
         {
             StopLoggingToChannel();
             LogError(e.ToString()).GetAwaiter().GetResult();
             Task.Delay(TimeSpan.FromMinutes(1)).GetAwaiter().GetResult();
             Shinoa.TryReenableLogging().GetAwaiter().GetResult();
         }
     }));
 }
예제 #5
0
        private async Task ProcessMessageReceived(SocketMessage arg)
        {
            try
            {
                SocketUserMessage message = arg as SocketUserMessage;
                if (message == null || message.Author.IsBot)
                {
                    return;
                }
                DiscordSocketClient client         = this._serviceProvider.GetService(typeof(DiscordSocketClient)) as DiscordSocketClient;
                CommandService      commandService = this._serviceProvider.GetService(typeof(CommandService)) as CommandService;

                int            pos     = 0;
                CommandContext context = new CommandContext(client, message);
                if (context.IsPrivate || message.HasMentionPrefix(client.CurrentUser, ref pos))
                {
                    IResult result = await commandService.ExecuteAsync(context, pos, this._serviceProvider);

                    if (!result.IsSuccess)
                    {
                        if (this.IsUserError(result.Error))
                        {
                            IMessageChannel dmChannel = await ChannelProvider.GetDMChannelAsync(context);

                            FormattedEmbedBuilder errorResponse = new FormattedEmbedBuilder()
                                                                  .AppendTitle($"{XayahReaction.Error} This didn't work")
                                                                  .AddField("Why, you ask?", result.ErrorReason);
                            await dmChannel.SendEmbedAsync(errorResponse);

                            await context.Message.AddReactionIfNotDMAsync(context, XayahReaction.Error);
                        }
                        else if (this.IsInterestingError(result.Error))
                        {
                            Logger.Debug($"Command failed: {result.ErrorReason}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
예제 #6
0
        private async Task ProcessClear()
        {
            try
            {
                IMessageChannel channel = await ChannelProvider.GetDMChannelAsync(this.Context);

                await this._remindService.ClearUserAsync(this.Context.User.Id);

                FormattedEmbedBuilder message = new FormattedEmbedBuilder()
                                                .AppendTitle($"{XayahReaction.Success} Done")
                                                .AppendDescription("I purged all of your reminders.");
                await channel.SendEmbedAsync(message);

                await this.Context.Message.AddReactionIfNotDMAsync(this.Context, XayahReaction.Envelope);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
예제 #7
0
        private async Task ProcessItem(string name)
        {
            try
            {
                if (this.IsDisabled())
                {
                    this.NotifyDisabledCommand();
                    return;
                }
                IMessageChannel channel = await ChannelProvider.GetDMChannelAsync(this.Context);

                FormattedEmbedBuilder message = await ItemDataBuilder.BuildAsync(name);

                await channel.SendEmbedAsync(message);

                await this.Context.Message.AddReactionIfNotDMAsync(this.Context, XayahReaction.Envelope);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
예제 #8
0
        private async Task ProcessHelp(string text)
        {
            try
            {
                text = this.TrimText(text);
                IMessageChannel channel = await ChannelProvider.GetDMChannelAsync(this.Context);

                FormattedEmbedBuilder message = new FormattedEmbedBuilder()
                                                .AppendTitle("Xayah Bot Help");
                switch (NumberUtil.StripForNumber(text))
                {
                case 1:
                    this.Append8BallHelp(message);
                    break;

                case 2:
                    this.AppendRemindHelp(message);
                    break;

                case 3:
                    this.AppendRiotDataHelp(message);
                    break;

                default:
                    this.AppendGeneralHelp(message);
                    break;
                }
                await channel.SendEmbedAsync(message);

                await this.Context.Message.AddReactionIfNotDMAsync(this.Context, XayahReaction.Envelope);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }