示例#1
0
 public static StoredMessagesService GetMessagesService(ulong guildId)
 {
     if (!storedMessages.TryGetValue(guildId, out StoredMessagesService messagesService))
     {
         messagesService = new StoredMessagesService(guildId);
         messagesService.AttemptLoad();
     }
     return(messagesService);
 }
示例#2
0
        internal static Task Client_MessageReceived(SocketMessage arg)
        {
            SocketUserMessage userMessage = arg as SocketUserMessage;

            if (userMessage != null)
            {
                SocketTextChannel guildChannel = userMessage.Channel as SocketTextChannel;

                if (userMessage.Content.StartsWith(storedMessagePrefix) && userMessage.Content.Length > storedMessagePrefix.Length && guildChannel != null)
                {
                    StoredMessagesService messagesService = GetMessagesService(guildChannel.Guild.Id);

                    string msg = userMessage.Content.Substring(storedMessagePrefix.Length);

                    if (messagesService.QuoteCount > 0)
                    {
                        if (int.TryParse(msg, out int quoteId))
                        {
                            if (quoteId > 0)
                            {
                                if (messagesService.TryGetQuote(quoteId, out Quote quote))
                                {
                                    return(userMessage.Channel.SendEmbedAsync(quote));
                                }
                            }
                        }
                    }

                    if (messagesService.TryGetMacro(msg, out Macro macro))
                    {
                        if (!macro.Build(out EmbedBuilder embed, out string messageContent, out string error))
                        {
                            return(userMessage.Channel.SendEmbedAsync($"Macro corrupted! `{error}`", true));
                        }
                        return(userMessage.Channel.SendMessageAsync(text: messageContent, embed: embed.Build()));
                    }

                    return(userMessage.AddReactionAsync(UnicodeEmoteService.Question));
                }
            }
            return(Task.CompletedTask);
        }
示例#3
0
        public Quote(ulong guildId, IMessage msg)
        {
            StoredMessagesService guildMessageService = StoredMessagesService.GetMessagesService(guildId);

            List <IAttachment> attachments = new List <IAttachment>(msg.Attachments);

            QuoteId        = 0;
            GuildId        = guildId;
            ChannelName    = msg.Channel.Name;
            ChannelId      = msg.Channel.Id;
            MessageId      = msg.Id;
            MessageContent = msg.Content;
            AuthorId       = msg.Author.Id;
            AuthorName     = msg.Author.ToString();
            Timestamp      = msg.Timestamp;
            if (attachments.Count > 0)
            {
                ImageURL = attachments[0].Url;
            }
            else
            {
                string attachment = null;
                foreach (string word in msg.Content.Split(' ', StringSplitOptions.RemoveEmptyEntries))
                {
                    word.Trim();
                    if (word.IsValidImageURL())
                    {
                        attachment = word;
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(attachment))
                {
                    ImageURL = attachment;
                }
            }
        }