Exemple #1
0
        public async Task Add(CommandContext e, [Description("Give the ID of the channel you wish to create from the !instance channels command.")] int channelID)
        {
            InstanceObject.ChannelTemplate template = RPClass.ChannelTemplates.FirstOrDefault(x => x.Id == channelID);
            if (template != null)
            {
                int instanceID = 1;
                if (RPClass.InstanceList.Count > 0)
                {
                    instanceID = RPClass.InstanceList.Last().Id + 1;
                }

                DiscordChannel c = await e.Guild.CreateChannelAsync(instanceID + "-" + template.Name, ChannelType.Text, parent : RPClass.InstanceCategory);

                RPClass.InstanceList.Add(new InstanceObject.RootObject(instanceID, c.Id, template.Id));
                if (template.Content.Count > 0)
                {
                    foreach (string content in template.Content)
                    {
                        await c.SendMessageAsync(content);
                    }
                }
                RPClass.SaveData(7);
                await e.RespondAsync("Channel: " + template.Name + " created with ID: " + instanceID + ".");
            }
            else
            {
                await e.RespondAsync("Enter a valid channel ID.");
            }
        }
Exemple #2
0
        public async Task RemoveMember(CommandContext e, [Description("Member to be removed ")] DiscordMember user, [RemainingText, Description("Name of faction which the user will be removed from.")] string guildName)
        {
            try
            {
                var guild  = RPClass.Guilds.First(x => x.Name == guildName);
                var rpUser = RPClass.Users.First(x => x.UserData.UserID == user.Id);
                if (rpUser.UserData.FactionID != guild.Id)
                {
                    await e.RespondAsync("User not in faction.");

                    return;
                }

                rpUser.UserData.FactionID = guild.Id;
                await XPClass.UpdatePlayerRanking(e.Guild);

                await XPClass.UpdateGuildRanking(e.Guild);

                RPClass.SaveData(3);
                RPClass.SaveData(1);
                await e.RespondAsync("User removed from faction.");
            }
            catch
            {
                await e.RespondAsync("No faction found with that name. Are you sure you typed it in correctly?");
            }
        }
Exemple #3
0
        public async Task RemoveMember(CommandContext e, [Description("Member to be removed ")] DiscordMember user, [RemainingText, Description("Name of guild which the user will be removed from.")] string guildName)
        {
            try
            {
                RPClass.Guilds.First(x => x.Name == guildName).UserIDs.Remove(RPClass.Users.First(x => x.UserData.UserID == user.Id).UserData.UserID);
                RPClass.Users.First(x => x.UserData.UserID == user.Id).UserData.GuildID = 0;
                if (RPClass.Users.First(x => x.UserData.UserID == user.Id).UserData.Role == 1)
                {
                    await XPClass.UpdatePlayerRanking(e.Guild, 1);
                }
                else if (RPClass.Users.First(x => x.UserData.UserID == user.Id).UserData.Role == 2)
                {
                    await XPClass.UpdatePlayerRanking(e.Guild, 2);
                }
                else if (RPClass.Users.First(x => x.UserData.UserID == user.Id).UserData.Role == 3)
                {
                    await XPClass.UpdatePlayerRanking(e.Guild, 3);
                }
                else if (RPClass.Users.First(x => x.UserData.UserID == user.Id).UserData.Role == 4)
                {
                    await XPClass.UpdatePlayerRanking(e.Guild, 4);
                }

                await XPClass.UpdateGuildRanking(e.Guild);

                RPClass.SaveData(3);
                RPClass.SaveData(1);
                await e.RespondAsync("User removed from guild.");
            }
            catch
            {
                await e.RespondAsync("No guild found with that name. Are you sure you typed it in correctly?");
            }
        }
Exemple #4
0
        private async Task Discord_SocketError(SocketErrorEventArgs e)
        {
            try
            {
                await(await e.Client.GetChannelAsync(392429153909080065)).SendMessageAsync("Not Restarting(test): Socket Error");
            }
            catch
            {
            }
            RPClass.SaveData(-1);

            /*
             * var process = new Process()
             * {
             *  StartInfo = new ProcessStartInfo
             *  {
             *      FileName = "/bin/bash",
             *      Arguments = $"-c \"dotnet RPBot-Core.dll\"",
             *      RedirectStandardOutput = true,
             *      UseShellExecute = false,
             *      CreateNoWindow = true,
             *  }
             * };
             * process.Start();
             * Environment.Exit(-1);
             * await Task.Delay(0);
             */
        }
Exemple #5
0
        public async Task Destroy(CommandContext e, [RemainingText, Description("Name of guild to be destroyed.")] string guildName)
        {
            try
            {
                foreach (UserObject.RootObject user in RPClass.Users.FindAll(x => x.UserData.GuildID == RPClass.Guilds.First(y => y.Name == guildName).Id))
                {
                    user.UserData.GuildID = 0;
                }
                RPClass.Guilds.Remove(RPClass.Guilds.First(x => x.Name == guildName));
                await XPClass.UpdatePlayerRanking(e.Guild, 1);

                await XPClass.UpdatePlayerRanking(e.Guild, 2);

                await XPClass.UpdatePlayerRanking(e.Guild, 3);

                await XPClass.UpdatePlayerRanking(e.Guild, 4);

                await XPClass.UpdateGuildRanking(e.Guild);

                RPClass.SaveData(3);
                RPClass.SaveData(1);

                await e.RespondAsync("Guild deleted.");
            }
            catch
            {
                await e.RespondAsync("No guild found with that name. Are you sure you typed it in correctly?");
            }
        }
Exemple #6
0
        private async Task Discord_SocketError(SocketErrorEventArgs e)
        {
            try
            {
                await RPClass.LogChannel.SendMessageAsync("Restarting: Socket Error");
            }
            catch
            {
            }
            RPClass.SaveData(-1);
            var process = new Process()
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName  = "/bin/bash",
                    Arguments = $"-c \"dotnet RPBot-Core.dll\"",
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                }
            };

            process.Start();
            Environment.Exit(-1);
            await Task.Delay(0);
        }
Exemple #7
0
        public async Task RPLock(CommandContext e, [Description("Member to be muted")] DiscordMember user)
        {
            try
            {
                UserObject.RootObject userObject = RPClass.Users.First(x => x.UserData.UserID == user.Id);

                if (userObject.ModData.IsMuted == 2)
                {
                    userObject.ModData.IsMuted = 0;
                    await user.ReplaceRolesAsync(userObject.ModData.Roles);

                    await e.RespondAsync("User un rp-locked.");
                }
                else if (userObject.ModData.IsMuted == 1)
                {
                    await e.RespondAsync("Fail: user is muted.");

                    return;
                }
                else
                {
                    userObject.ModData.IsMuted = 2;
                    userObject.ModData.Roles   = user.Roles.ToList();
                    await user.ReplaceRolesAsync(new List <DiscordRole>() { RPClass.RPLockRole });

                    await e.RespondAsync("User rplocked.");
                }
                RPClass.SaveData(1);
            }
            catch
            {
                await e.RespondAsync("NO");
            }
        }
Exemple #8
0
        public async Task ShowCard(CommandContext e, [Description("Name of the character")] string characterName, [Description("Role - 'Hero', 'Villain' or 'Rogue'")] string role,
                                   [Description("Image for the front - URL")] string frontImage,
                                   [Description("Icon for the back - URL")] string backImage, [Description("Hex colour of background")] string hex, [Description("Location of birth")] string born, [Description("Height (feet & inches)")] string height, [Description("Weight (kg)")] string weight,
                                   [Description("Quirk name")] string quirk, [Description("Power (/5)")] string power, [Description("Intelligence (/5)")] string intelligence, [Description("Speed (/5)")] string speed,
                                   [Description("Agility (/5)")] string agility, [Description("Technique (/5)")] string technique, [Description("Precision (/5)")] string precision, [Description("Quote title")] string quoteTitle,
                                   [Description("Quote content")] string quote)
        {
            if (File.Exists($"Cards/Done/front-{characterName}.png"))
            {
                await e.RespondAsync("Card already exists. Use the command `!card delete NAME`.");

                return;
            }

            Roles r = Roles.Hero;

            if (role == "Hero")
            {
                r = Roles.Hero;
            }
            else if (role == "Villain")
            {
                r = Roles.Villain;
            }
            else if (role == "Rogue")
            {
                r = Roles.Rogue;
            }
            else
            {
                await e.RespondAsync("Invalid role type.");

                return;
            }
            string fileStamp = DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss");

            using (WebClient webClient = new WebClient())
            {
                webClient.DownloadFile(frontImage, $"Cards/frontimage-{fileStamp}.png");
            }
            string front = GenerateFront(characterName, r, $"Cards/frontimage-{fileStamp}.png");

            using (WebClient webClient = new WebClient())
            {
                webClient.DownloadFile(backImage, $"Cards/backimage-{fileStamp}.png");
            }

            string back = GenerateBack($"Cards/backimage-{fileStamp}.png", hex, r, characterName, born, height, weight, quirk, power, intelligence, speed, agility, technique, precision, quoteTitle, quote);

            RPClass.CardList.Add(characterName, $"{front}¬{back}");
            await e.RespondWithFileAsync(front);

            await e.RespondWithFileAsync(back);

            await e.Message.DeleteAsync();

            File.Delete($"Cards/frontimage-{fileStamp}.png");
            File.Delete($"Cards/backimage-{fileStamp}.png");
            RPClass.SaveData(5);
        }
Exemple #9
0
        public async Task Bulk(CommandContext e)
        {
            await e.RespondAsync("Change stats by typing `<mention> <xp amount>.\nTo end this process and save, type `stop`.");

            var interactivity = e.Client.GetInteractivity();

AnotherMessage:

            var msg = await interactivity.WaitForMessageAsync(x => x.Author == e.Member, TimeSpan.FromSeconds(120));

            if (msg != null)
            {
                if (msg.Message.Content == "stop")
                {
                    await UpdateStats(RPClass.StatsChannel);

                    RPClass.SaveData(1);
                    await UpdatePlayerRanking(e.Guild, 1);
                    await UpdatePlayerRanking(e.Guild, 2);
                    await UpdatePlayerRanking(e.Guild, 3);
                    await UpdatePlayerRanking(e.Guild, 4);

                    await e.RespondAsync("Stats updated.");
                }
                else
                {
                    try
                    {
                        string[]      args   = msg.Message.Content.Split(" ");
                        DiscordMember member = await e.CommandsNext.ConvertArgument(args[0], e, typeof(DiscordMember)) as DiscordMember;

                        UserObject.RootObject userData = RPClass.Users.Find(x => x.UserData.UserID == member.Id);
                        userData.Xp += int.Parse(args[1]);
                        if (userData.Xp < 0)
                        {
                            userData.Xp = 0;
                        }
                        await e.RespondAsync("Stat changed. \nSend another, by typing `-<mention> <xp amount>`.\nTo end this process, type `stop`.");
                    }
                    catch
                    {
                        await e.RespondAsync("No user found, or xp was in invalid format.");
                    }
                    goto AnotherMessage;
                }
            }
            else
            {
                await UpdateStats(RPClass.StatsChannel);

                RPClass.SaveData(1);
                await UpdatePlayerRanking(e.Guild, 1);
                await UpdatePlayerRanking(e.Guild, 2);
                await UpdatePlayerRanking(e.Guild, 3);
                await UpdatePlayerRanking(e.Guild, 4);

                await e.RespondAsync("Stats updated.");
            }
        }
Exemple #10
0
        public async Task Create(CommandContext e, [RemainingText, Description("Name of new faction")] string guildName)
        {
            RPClass.Guilds.Add(new GuildObject.RootObject(1 + RPClass.Guilds.Count, guildName));
            await XPClass.UpdateGuildRanking(e.Guild);

            RPClass.SaveData(3);
            await e.RespondAsync("Guild created.");
        }
Exemple #11
0
        public async Task Give(CommandContext e, [Description("Who to award the money to")] DiscordMember user, [Description("Amount of money to award")] int money = -1)
        {
            if (money > 0)
            {
                RPClass.Users.Find(x => x.UserData.UserID == user.Id).UserData.Money += money;
                UserObject.RootObject a = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                await e.RespondAsync("User: "******" now has $" + a.UserData.Money);

                RPClass.SaveData(1);
            }
        }
Exemple #12
0
        public async Task Give(CommandContext e, [Description("Who to award the merit points to")] DiscordMember user, [Description("Amount of merit points to award")] int meritPoints = -1)
        {
            if (meritPoints > 0)
            {
                RPClass.Users.Find(x => x.UserData.UserID == user.Id).UserData.MeritPoints += meritPoints;
                UserObject.RootObject a = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                await e.RespondAsync("User: "******" now has " + a.UserData.MeritPoints + " merit points.");

                RPClass.SaveData(1);
            }
        }
Exemple #13
0
        public async Task Give(CommandContext e, [Description("Who to award the unicurs to")] DiscordMember user, [Description("Amount of unicurs to award")] int money = -1)
        {
            if (money > 0)
            {
                RPClass.Users.Find(x => x.UserData.UserID == user.Id).UserData.Money += money;
                UserObject.RootObject a = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                await e.RespondAsync($"User: {user.DisplayName} now has {a.UserData.Money} Unicur(s)");

                RPClass.SaveData(1);
            }
        }
Exemple #14
0
        public async Task UltimateMute(CommandContext e, [Description("Member to be muted")] DiscordMember user, bool silent = false)
        {
            try
            {
                UserObject.RootObject userObject = RPClass.Users.First(x => x.UserData.UserID == user.Id);

                if (userObject.ModData.IsMuted == 2)
                {
                    if (!silent)
                    {
                        await e.RespondAsync("Fail: user is RP Locked.");
                    }
                    return;
                }
                else if (userObject.ModData.IsMuted == 1)
                {
                    userObject.ModData.IsMuted = 0;
                    await user.ReplaceRolesAsync(userObject.ModData.Roles);

                    if (!silent)
                    {
                        await e.RespondAsync("User unmuted.");
                    }
                }
                else
                {
                    if (user.Roles.Any(x => x == RPClass.AdminRole) && !e.Member.Roles.Any(x => x == RPClass.AdminRole))
                    {
                        if (!silent)
                        {
                            await e.RespondAsync("Admins are the master race, leave us alone.");
                        }
                        return;
                    }
                    userObject.ModData.IsMuted = 1;
                    userObject.ModData.Roles   = user.Roles.ToList();
                    await user.ReplaceRolesAsync(new List <DiscordRole>() { RPClass.MuteRole });

                    if (!silent)
                    {
                        await e.RespondAsync("User muted.");
                    }
                }
                RPClass.SaveData(1);
            }
            catch
            {
                if (!silent)
                {
                    await e.RespondAsync("NO");
                }
            }
        }
Exemple #15
0
        public async Task Comment(CommandContext e, [Description("User to change comment of")] DiscordMember user, [RemainingText, Description("Comment for bounty, put '-' for no comment.")] string comment)
        {
            if (comment == "-")
            {
                comment = " ";
            }
            RPClass.Users.Find(x => x.UserData.UserID == user.Id).UserData.InfamyComment = comment;
            await Extensions.UpdateFameAndInfamy(0);

            RPClass.SaveData(1);
            await e.RespondAsync("Done!");
        }
Exemple #16
0
        public async Task Update(CommandContext e)
        {
            var members = await e.Guild.GetAllMembersAsync();

            foreach (var user in RPClass.Users.Where(x => x.UserData.Fame > 0 || x.UserData.Infamy > 0))
            {
                await Extensions.UpdateFameAndInfamyRoles(user.UserData.Fame, user.UserData.Infamy, members.First(x => x.Id == user.UserData.UserID), user.UserData.Role == 1?true : false);
            }
            await Extensions.UpdateFameAndInfamy(0);

            RPClass.SaveData(1);
            await e.RespondAsync("Done!");
        }
Exemple #17
0
        private async Task Run(string[] args)
        {
            /*  using (var db = new Context())
             * {
             *    db.Database.CreateIfNotExists();
             *    var user = new User() { UserID = 00001010101010, Characters = "oof", IsMuted = false, MutedRoles = "test" };
             *    db.Users.Add(user);
             *    db.SaveChanges();
             * }*/

            if (args.Any())
            {
                RPClass.Restarted = true;
            }
            RPClass.LoadData();
            var cfg  = new Config();
            var json = string.Empty;

            if (File.Exists("config.json"))
            {
                json = File.ReadAllText("config.json", new UTF8Encoding(false));
            }
            else if (File.Exists("../../config.json"))
            {
                json = File.ReadAllText("../../config.json", new UTF8Encoding(false));
            }
            else
            {
                json = JsonConvert.SerializeObject(cfg);
                File.WriteAllText("config.json", json, new UTF8Encoding(false));
                Console.WriteLine("Config file was not found, a new one was generated. Fill it with proper values and rerun this program");
                Console.ReadKey();

                return;
            }

            cfg = JsonConvert.DeserializeObject <Config>(json);

            var tskl = new List <Task>();

            for (var i = 0; i < cfg.ShardCount; i++)
            {
                var bot = new RPBot(cfg, i);
                tskl.Add(bot.RunAsync());
                await Task.Delay(7500);
            }

            await Task.WhenAll(tskl);

            await Task.Delay(-1);
        }
Exemple #18
0
        public async Task Remove(CommandContext e, [Description("Name of the tag "), RemainingText] string tagName)
        {
            if (RPClass.TagsList.Exists(x => x.Name == tagName.ToLower()))
            {
                RPClass.TagsList.Remove(RPClass.TagsList.Find(x => x.Name == tagName.ToLower()));
                await e.RespondAsync("Tag: " + tagName + " removed.");

                RPClass.SaveData(9);
            }
            else
            {
                await e.RespondAsync("No tag by that name found.");
            }
        }
Exemple #19
0
        public async Task Take(CommandContext e, [Description("Who to take the money from")] DiscordMember user, [Description("Amount of money to take")] int money = -1)
        {
            if (money > 0)
            {
                UserObject.RootObject userData = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                userData.UserData.Money -= money;
                if (userData.UserData.Money < 0)
                {
                    userData.UserData.Money = 0;
                }
                await e.RespondAsync("User: "******" now has $" + userData.UserData.Money);

                RPClass.SaveData(1);
            }
        }
Exemple #20
0
        public async Task Take(CommandContext e, [Description("Who to take the unicurs from")] DiscordMember user, [Description("Amount of unicurs to take")] int money = -1)
        {
            if (money > 0)
            {
                UserObject.RootObject userData = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                userData.UserData.Money -= money;
                if (userData.UserData.Money < 0)
                {
                    userData.UserData.Money = 0;
                }
                await e.RespondAsync($"User: {user.DisplayName} now has {userData.UserData.Money} Unicur(s)");

                RPClass.SaveData(1);
            }
        }
Exemple #21
0
        public async Task Take(CommandContext e, [Description("Who to take the merit points from")] DiscordMember user, [Description("Amount of merit points to take")] int meritPoints = -1)
        {
            if (meritPoints > 0)
            {
                UserObject.RootObject userData = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                userData.UserData.MeritPoints -= meritPoints;
                if (userData.UserData.MeritPoints < 0)
                {
                    userData.UserData.MeritPoints = 0;
                }
                await e.RespondAsync("User: "******" now has " + userData.UserData.MeritPoints + " merit points.");

                RPClass.SaveData(1);
            }
        }
Exemple #22
0
        public async Task ExecuteGroupAsync(CommandContext e, [Description("User to change stats of")] DiscordMember user, [Description("How much you wish to change it by")] int xpNum)
        {
            if (xpNum != 0)
            {
                UserObject.RootObject userData = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                userData.Xp += xpNum;
                if (userData.Xp < 0)
                {
                    userData.Xp = 0;
                }

                await UpdateStats(RPClass.StatsChannel);

                RPClass.SaveData(1);
                UserObject.RootObject newUserData = RPClass.Users.Find(x => x.UserData.UserID == user.Id);
                switch (newUserData.UserData.Role)
                {
                case 1:
                    await UpdatePlayerRanking(e.Guild, 1);

                    break;

                case 2:
                    await UpdatePlayerRanking(e.Guild, 2);

                    break;

                case 3:
                    await UpdatePlayerRanking(e.Guild, 3);

                    break;

                case 4:
                    await UpdatePlayerRanking(e.Guild, 4);

                    break;

                case 0:
                    await UpdatePlayerRanking(e.Guild, 1);
                    await UpdatePlayerRanking(e.Guild, 2);
                    await UpdatePlayerRanking(e.Guild, 3);
                    await UpdatePlayerRanking(e.Guild, 4);

                    break;
                }
                await e.RespondAsync("Stat changed.");
            }
        }
Exemple #23
0
        private Task Discord_PresenceUpdate(PresenceUpdateEventArgs e)
        {
            var user = RPClass.StatusList.FirstOrDefault(x => x.UserID == e.User.Id);

            if (user == null)
            {
                RPClass.StatusList.Add(new StatusObject.RootObject(e.User.Id));
                user = RPClass.StatusList.Last();
            }
            if (e.PresenceAfter != null)
            {
                user.AddStatus(DateTime.Now, e.PresenceAfter.Status);
                RPClass.SaveData(7);
            }

            return(Task.Delay(0));
        }
Exemple #24
0
        public async Task Destroy(CommandContext e, [Description("Quote the ID at the beginning of the channel name.")] int rpID)
        {
            InstanceObject.RootObject instance = RPClass.InstanceList.FirstOrDefault(x => x.Id == rpID);
            if (instance != null)
            {
                DiscordChannel c = e.Guild.GetChannel(instance.ChannelID);
                await c.DeleteAsync();

                RPClass.InstanceList.Remove(instance);
                RPClass.SaveData(7);
                await e.RespondAsync("Instance destroyed.");
            }
            else
            {
                await e.RespondAsync("Use the ID at the beginning of the channel name.");
            }
        }
Exemple #25
0
        public async Task AddTemplate(CommandContext e, [Description("Name of channel for template.")] string name, [Description("All text to be displayed at the start of the instance. Send in multiple messages, as the character limit is 2000. If there is more than one message, end the message with '¬' and start the next message with '¬'."), RemainingText] string content)
        {
            List <string> ContentList = new List <string>
            {
                content.Replace("¬", "")
            };

            if (content.Contains("¬"))
            {
                var interactivity = e.Client.GetInteractivity();

AnotherMessage:

                var msg = await interactivity.WaitForMessageAsync(x => x.Content.StartsWith("¬"), TimeSpan.FromSeconds(120));

                if (msg != null)
                {
                    await e.RespondAsync("Message added to end of template.");

                    string strippedContent = msg.Message.Content.Replace("¬", "");
                    ContentList.Add(strippedContent);
                    if (msg.Message.Content.EndsWith("¬"))
                    {
                        goto AnotherMessage;
                    }
                    else
                    {
                        RPClass.ChannelTemplates.Add(new InstanceObject.ChannelTemplate(RPClass.ChannelTemplates.Count + 1, name, ContentList));
                        RPClass.SaveData(6);
                        await e.RespondAsync("Template added and saved.");
                    }
                }
                else
                {
                    RPClass.ChannelTemplates.Add(new InstanceObject.ChannelTemplate(RPClass.ChannelTemplates.Count + 1, name, ContentList));
                    RPClass.SaveData(6);
                    await e.RespondAsync("Template added and saved.");
                }
            }
            else
            {
                RPClass.ChannelTemplates.Add(new InstanceObject.ChannelTemplate(RPClass.ChannelTemplates.Count + 1, name, ContentList));
                RPClass.SaveData(6);
                await e.RespondAsync("Template added and saved.");
            }
        }
Exemple #26
0
 public async Task DeleteCard(CommandContext e, [Description("Name of the character")] string characterName)
 {
     if (File.Exists($"Cards/Done/front-{characterName}.png"))
     {
         File.Delete($"Cards/Done/front-{characterName}.png");
     }
     if (File.Exists($"Cards/Done/back-{characterName}.png"))
     {
         File.Delete($"Cards/Done/back-{characterName}.png");
     }
     if (RPClass.CardList.Any(x => x.Key == characterName))
     {
         RPClass.CardList.Remove(characterName);
     }
     RPClass.SaveData(5);
     await e.RespondAsync("Done!");
 }
Exemple #27
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);
                            }
                        }
                    }
                }
            }
        }
Exemple #28
0
        public async Task End(CommandContext e, [Description("Quote the ID at the beginning of the channel name.")] int rpID)
        {
            InstanceObject.RootObject instance = RPClass.InstanceList.FirstOrDefault(x => x.Id == rpID);
            if (instance != null)
            {
                DiscordChannel c = e.Guild.GetChannel(instance.ChannelID);
                await c.AddOverwriteAsync(e.Guild.EveryoneRole, Permissions.ReadMessageHistory, Permissions.SendMessages);

                instance.Active = false;

                RPClass.SaveData(7);
                await e.RespondAsync("Instance closed.");
            }
            else
            {
                await e.RespondAsync("Use the ID at the beginning of the channel name.");
            }
        }
Exemple #29
0
        private async Task Run(string[] args)
        {
            //File.WriteAllText("test.txt", WikiTests.CreateInfoBox(new InfoBoxObject("jeff", "the slayer", "no<br>maybe<br>perhaps", "gay", "Single", 25, "23/02/2000", "North Pier", "South Pier", "Human", "Male", "182cm", "70kg", "Bright Blue", "Hot pink", new string[] { "Image 1", "Image 2", "Image 3" }, new string[] { "https://cdn.discordapp.com/attachments/447483115250909184/473256482616508436/image.jpg", "https://cdn.discordapp.com/attachments/447483115250909184/473257220813881344/image.jpg", "https://cdn.discordapp.com/attachments/455019174385942530/472809787780759562/a7a1c3d8cffc5dff31021d5cfd3a135f.png" })));
            if (args.Any())
            {
                RPClass.Restarted = true;
            }
            RPClass.LoadData();
            var cfg  = new Config();
            var json = string.Empty;

            if (File.Exists("config.json"))
            {
                json = File.ReadAllText("config.json", new UTF8Encoding(false));
            }
            else if (File.Exists("../../config.json"))
            {
                json = File.ReadAllText("../../config.json", new UTF8Encoding(false));
            }
            else
            {
                json = JsonConvert.SerializeObject(cfg);
                File.WriteAllText("config.json", json, new UTF8Encoding(false));
                Console.WriteLine("Config file was not found, a new one was generated. Fill it with proper values and rerun this program");
                Console.ReadKey();

                return;
            }

            cfg = JsonConvert.DeserializeObject <Config>(json);

            var tskl = new List <Task>();

            for (var i = 0; i < cfg.ShardCount; i++)
            {
                var bot = new RPBot(cfg, i);
                tskl.Add(bot.RunAsync());
                await Task.Delay(7500);
            }

            await Task.WhenAll(tskl);

            await Task.Delay(-1);
        }
Exemple #30
0
        public async Task Restart(CommandContext e)
        {
            RPClass.SaveData(-1);
            var process = new Process()
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName  = "/bin/bash",
                    Arguments = $"-c \"dotnet RPBot-Core.dll\"",
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                }
            };

            process.Start();
            Environment.Exit(-1);
            await Task.Delay(0);
        }