コード例 #1
0
ファイル: CommandsClass.cs プロジェクト: jcryer/RPBot
        public async Task Name(CommandContext e, [Description("What to call yourself")] string name = "")
        {
            DiscordMessage x;

            if (name == "off")
            {
                SpeechObject.RootObject savedName = RPClass.SpeechList.FirstOrDefault(y => y.Id == e.Member.Id);
                if (savedName != null)
                {
                    RPClass.SpeechList.Remove(savedName);
                    x = await e.RespondAsync("Removed from list.");
                }
                else
                {
                    x = await e.RespondAsync("");
                }
                await Task.Delay(2000);

                await e.Message.DeleteAsync();

                await x.DeleteAsync();
            }
            else if (name != "")
            {
                SpeechObject.RootObject savedName = RPClass.SpeechList.FirstOrDefault(y => y.Id == e.Member.Id);
                if (savedName != null)
                {
                    RPClass.SpeechList.Remove(savedName);
                }
                RPClass.SpeechList.Add(new SpeechObject.RootObject(e.Member.Id, name));
                x = await e.RespondAsync("Name changed.");

                await Task.Delay(2000);

                await e.Message.DeleteAsync();

                await x.DeleteAsync();
            }
            else
            {
                x = await e.RespondAsync("Specify a name.");

                await Task.Delay(2000);

                await e.Message.DeleteAsync();

                await x.DeleteAsync();
            }
        }
コード例 #2
0
ファイル: RPBot.cs プロジェクト: jcryer/RPBot
        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
                        {
                        }
                    }
                }
            }
        }