Exemplo n.º 1
0
        public async Task Discord_MessageCreated(MessageCreateEventArgs e)
        {
            if (e.Guild == RPClass.RPGuild)
            {
                if (RPClass.FirstRun)
                {
                    try
                    {
                        RPClass.FirstRun = false;

                        Thread myNewThread = new Thread(async() => await RPClass.UpdateClock(e, Discord));
                        myNewThread.Start();
                    }
                    catch { }
                }
                if (!e.Message.Content.StartsWith("!"))
                {
                    if (e.Message.ChannelId == 312918289988976653 && e.Author.Id != e.Client.CurrentUser.Id)
                    {
                        if (RPClass.slowModeTime > 0)
                        {
                            var u = RPClass.slowModeList.FirstOrDefault(x => x.Key == e.Message.Author);
                            if (u.Key != null)
                            {
                                if (Math.Abs((u.Value - DateTime.UtcNow).TotalSeconds) <= RPClass.slowModeTime)
                                {
                                    if (!(e.Author as DiscordMember).Roles.Any(x => x == RPClass.AdminRole))
                                    {
                                        await e.Message.DeleteAsync();
                                    }
                                }
                                else
                                {
                                    RPClass.slowModeList[e.Message.Author as DiscordMember] = DateTime.UtcNow;
                                }
                            }
                            else
                            {
                                RPClass.slowModeList.Add(e.Message.Author as DiscordMember, DateTime.UtcNow);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task Discord_MessageCreated(MessageCreateEventArgs e)
        {
            if (e.Guild == RPClass.RPGuild)
            {
                if (RPClass.FirstRun)
                {
                    try
                    {
                        RPClass.FirstRun = false;
                        Thread myNewThread = new Thread(async() => await RPClass.UpdateClock(e, Discord));
                        myNewThread.Start();
                    }
                    catch { }
                }

                if (!e.Message.Content.StartsWith("!"))
                {
                    if (e.Channel.ParentId.HasValue)
                    {
                        if (RPClass.RPCategories.Contains(e.Channel.ParentId.Value))
                        {
                            var user = RPClass.Users.FirstOrDefault(x => x.UserData.UserID == e.Author.Id);
                            if (user != null)
                            {
                                user.Activity.CharacterCount += e.Message.Content.Length;
                                user.Activity.MessageCount   += 1;
                                user.Activity.WordCount      += CountWords(e.Message.Content);
                            }
                        }
                    }
                    if ((e.Author as DiscordMember).Roles.Any(x => x == RPClass.StaffRole))
                    {
                        MatchCollection matchList = Regex.Matches(e.Message.Content, "`{0,3}{{(.+?)}}`{0,3}");
                        var             list      = matchList.Cast <Match>().Select(match => match.Value).ToList();
                        int             changes   = 0;
                        if (list.Any())
                        {
                            string content = e.Message.Content;
                            var    roles   = new List <DiscordRole>();
                            foreach (var ping in list)
                            {
                                if (ping.Contains("`"))
                                {
                                    continue;
                                }
                                var pingCut = ping.Substring(2, ping.Length - 4);

                                if (e.Guild.Roles.Any(x => x.Name == pingCut))
                                {
                                    var role = e.Guild.Roles.First(x => x.Name == pingCut);
                                    if (!role.IsMentionable)
                                    {
                                        try
                                        {
                                            await role.UpdateAsync(mentionable : true);

                                            roles.Add(role);
                                        }
                                        catch (Exception exception) { }
                                    }
                                    content = content.Replace(ping, role.Mention);
                                    changes++;
                                }
                            }
                            if (changes != 0)
                            {
                                await e.Channel.SendMessageAsync(content);

                                await e.Message.DeleteAsync();

                                foreach (var role in roles)
                                {
                                    await role.UpdateAsync(mentionable : false);
                                }
                            }
                        }
                    }

                    if (RPClass.SpeechList.Any(x => x.Id == e.Author.Id) && !e.Message.Content.StartsWith("*"))
                    {
                        SpeechObject.RootObject savedName = RPClass.SpeechList.First(x => x.Id == e.Author.Id);
                        await e.Message.DeleteAsync();

                        await e.Channel.SendMessageAsync("__**" + savedName.Name + "**__: " + e.Message.Content);
                    }
                    else if (e.Message.Content.StartsWith("~") && !(e.Message.Content[1] == '~'))
                    {
                        try
                        {
                            string[] msg = e.Message.Content.Split(new char[] { ' ' }, 2);
                            await e.Message.RespondAsync("__**" + msg[0].Replace("~", "") + "**__: " + msg[1]);

                            await e.Message.DeleteAsync();
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }