コード例 #1
0
        static async Task ProcessMessage(Discord.IMessage message)
        {
            if (message.Author.Id == DiscordClient.CurrentUser.Id)
            {
                return;
            }

            var server = Config.Servers.SingleOrDefault(a => a.ChannelIds.Contains(message.Channel.Id));

            if (server == null)
            {
                return;
            }

            if (server.AllowQuotes && await HandleQuote(message))
            {
                return;
            }

            var res = await GetResponse(message.Content, message.Author.Discriminator);

            if (res != null)
            {
                var msg = await message.Channel.SendMessageAsync("", false, res);

                SentMessages.TryAdd(message.Id, msg);
            }
        }
コード例 #2
0
        static async Task <bool> HandleQuote(Discord.IMessage msg)
        {
            try
            {
                if (!msg.Content.StartsWith("!quote "))
                {
                    return(false);
                }

                var msgSplit = msg.Content.Split(' ');
                if (msgSplit.Length < 2)
                {
                    return(true);
                }

                string verb = msgSplit[1];

                switch (verb)
                {
                case "show":
                    if (int.TryParse(TextAfter(msg.Content, "show").Trim(), out var quoteNum))
                    {
                        await Quotes.DisplayQuote(quoteNum, msg.Channel);
                    }
                    break;

                case "find":
                    var text = TextAfter(msg.Content, "find").Trim();
                    if (text.Length > 0)
                    {
                        await Quotes.DisplayFindQuote(text, msg.Channel);
                    }
                    break;

                case "add":
                    var toAdd = TextAfter(msg.Content, "add").Trim();
                    if (toAdd.Length > 0)
                    {
                        await Quotes.DisplayAddQuote(toAdd, msg.Channel);
                    }
                    break;

                case "dump":
                    await Quotes.DumpQuotes(msg.Channel);

                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error handling quote: {0}", e);
            }

            return(true);
        }
コード例 #3
0
        public static async Task <DiscordMessage> CreateOrGetAsync(Discord.IMessage message)
        {
            var db = new ApplicationDataContext();
            var dm = db.DiscordMessages.Where(m => m.Id == message.Id).FirstOrDefault();

            db.Dispose();
            if (dm == null)
            {
                await CreateAsync(message);
            }
            return(dm);
        }
コード例 #4
0
        public static async Task <DiscordMessage> CreateAsync(Discord.IMessage message)
        {
            await DiscordChannel.CreateOrGetAsync(message.Channel);

            using (var db = new ApplicationDataContext())
            {
                var dm = new DiscordMessage()
                {
                    Id = message.Id, AuthorId = message.Author.Id, ChannelId = message.Channel.Id, Created = DateTime.Now, IsDeleted = false, Text = message.Content
                };
                db.Add(dm);
                await db.SaveChangesAsync();

                return(dm);
            }
        }
コード例 #5
0
ファイル: DiscordMessage.cs プロジェクト: PDFer/TGRaidBot
 public DiscordMessage(Discord.IMessage message)
 {
     //MessageId = message.Id;
     Content = message;
 }