public static async Task LoadMissionSettings()
        {
            LoadFileOperation operation = await ResourcesModel.LoadToJSONObject(ResourcesModel.MissionSettingsFilePath);

            if (operation.Success)
            {
                JSONObject json = operation.Result;
                json.GetField(ref lastMissionNumber, JSON_MISSIONNUMBER);
                string text = "";
                string jMissionCategoryID = "";
                json.GetField(ref jMissionCategoryID, JSON_MISSIONCATEGORYID);
                ulong.TryParse(jMissionCategoryID, out MissionCategoryId);
                if (json.GetField(ref text, JSON_DEFAULTTOPIC))
                {
                    DefaultTopic = text;
                }
                if (json.GetField(ref text, JSON_EXPLORERQUESTIONS))
                {
                    ExplorerQuestions = text;
                }
                if (json.GetField(ref text, JSON_TESTIMONIALPROMPT))
                {
                    TestimonialPrompt = text;
                }
                if (json.GetField(ref text, JSON_FILEREPORTPROMPT))
                {
                    FileReportPrompt = text;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves all settings to appdata/locallow/Ciridium Wing Bot/Settings.json
        /// </summary>
        internal static async Task SaveSettings()
        {
            JSONObject json = new JSONObject();

            json.AddField(JSON_BOTTOKEN, token);
            JSONObject adminIDs = new JSONObject();

            foreach (var adminID in botAdminIDs)
            {
                adminIDs.Add(adminID.ToString());
            }
            json.AddField(JSON_ADMINIDS, adminIDs);
            JSONObject debugSettings = new JSONObject();

            foreach (bool b in debugLogging)
            {
                debugSettings.Add(b);
            }
            json.AddField(JSON_ENABLEDEBUG, debugSettings);
            json.AddField(JSON_DEBUGCHANNEL, DebugMessageChannelId.ToString());
            json.AddField(JSON_WELCOMINGCHANNEL, WelcomeMessageChannelId.ToString());
            json.AddField(JSON_WELCOMINGMESSAGE, welcomingMessage);
            json.AddField(JSON_MODERATORROLE, ModeratorRole.ToString());
            json.AddField(JSON_PILOTROLE, EscortPilotRole.ToString());
            json.AddField(JSON_BOTDEVROLE, BotDevRole.ToString());
            json.AddField(JSON_DISPATCHROLE, DispatchRole.ToString());
            json.AddField(JSON_INARA_APIKEY, Inara_APIkey);
            json.AddField(JSON_PREFIX, CommandService.Prefix);


            await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.SettingsFilePath, json);
        }
Esempio n. 3
0
        public static async Task SaveMissions()
        {
            JSONObject json = new JSONObject();

            foreach (ulong mission in missionList)
            {
                json.Add(mission.ToString());
            }
            await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.MissionsFilePath, json);
        }
        public static async Task SaveMissionSettings()
        {
            JSONObject json = new JSONObject();

            json.AddField(JSON_MISSIONNUMBER, lastMissionNumber);
            json.AddField(JSON_MISSIONCATEGORYID, MissionCategoryId.ToString());
            json.AddField(JSON_DEFAULTTOPIC, DefaultTopic);
            json.AddField(JSON_EXPLORERQUESTIONS, ExplorerQuestions);
            json.AddField(JSON_TESTIMONIALPROMPT, TestimonialPrompt);
            json.AddField(JSON_FILEREPORTPROMPT, FileReportPrompt);
            await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.MissionSettingsFilePath, json);
        }
Esempio n. 5
0
        public static async Task LoadMissions()
        {
            LoadFileOperation operation = await ResourcesModel.LoadToJSONObject(ResourcesModel.MissionsFilePath);

            if (operation.Success)
            {
                JSONObject json = operation.Result;
                if (json.IsArray)
                {
                    foreach (JSONObject jMission in json.list)
                    {
                        ulong nId;
                        if (ulong.TryParse(jMission.str, out nId))
                        {
                            missionList.Add(nId);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Loads and applies Settings from appdata/locallow/Ciridium Wing Bot/Settings.json
        /// </summary>
        /// <returns></returns>
        private static async Task loadSettings()
        {
            LoadFileOperation operation = await ResourcesModel.LoadToJSONObject(ResourcesModel.SettingsFilePath);

            if (operation.Success)
            {
                JSONObject json = operation.Result;
                if (json.GetField(ref token, JSON_BOTTOKEN) && json.HasField(JSON_ADMINIDS))
                {
                    JSONObject botadmins = json[JSON_ADMINIDS];
                    if (botadmins.IsArray && botadmins.list != null)
                    {
                        foreach (var admin in botadmins.list)
                        {
                            ulong nID;
                            if (ulong.TryParse(admin.str, out nID))
                            {
                                botAdminIDs.Add(nID);
                            }
                        }
                    }
                    if (json.HasField(JSON_ENABLEDEBUG))
                    {
                        JSONObject debugSettings = json[JSON_ENABLEDEBUG];
                        if (debugSettings.IsArray)
                        {
                            for (int i = 0; i < debugSettings.list.Count; i++)
                            {
                                debugLogging[i] = debugSettings.list[i].b;
                            }
                        }
                    }
                    string id = "";
                    if (json.GetField(ref id, JSON_DEBUGCHANNEL))
                    {
                        ulong.TryParse(id, out DebugMessageChannelId);
                    }
                    if (json.GetField(ref id, JSON_WELCOMINGCHANNEL))
                    {
                        ulong.TryParse(id, out WelcomeMessageChannelId);
                    }
                    json.GetField(ref welcomingMessage, JSON_WELCOMINGMESSAGE);
                    if (json.GetField(ref id, JSON_MODERATORROLE))
                    {
                        ulong.TryParse(id, out ModeratorRole);
                    }
                    if (json.GetField(ref id, JSON_PILOTROLE))
                    {
                        ulong.TryParse(id, out EscortPilotRole);
                    }
                    if (json.GetField(ref id, JSON_BOTDEVROLE))
                    {
                        ulong.TryParse(id, out BotDevRole);
                    }
                    if (json.GetField(ref id, JSON_DISPATCHROLE))
                    {
                        ulong.TryParse(id, out DispatchRole);
                    }
                    json.GetField(ref Inara_APIkey, JSON_INARA_APIKEY);
                    string prefix_str = string.Empty;
                    if (json.GetField(ref prefix_str, JSON_PREFIX))
                    {
                        if (prefix_str.Length > 0)
                        {
                            CommandService.Prefix = prefix_str[0];
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a new mission channel
        /// </summary>
        /// <param name="channel_name_suffix">The suffix added to the channel name</param>
        /// <param name="explorers">All explorers to be part of this new mission channel</param>
        /// <param name="guild">The guild containing the mission channel category</param>
        /// <param name="source">The user that issued the createmission command</param>
        /// <returns>The RestTextChannel created by the command</returns>
        public static async Task <RestTextChannel> CreateMission(string channel_name_suffix, IReadOnlyCollection <SocketUser> explorers, SocketGuild guild, SocketUser source)
        {
            int failcode = 0;

            try
            {
                // [00] retrieving mission number and other variables
                int    missionnumber = MissionSettingsModel.NextMissionNumber;
                string channelname   = string.Format("mission_{0}_{1}", missionnumber, channel_name_suffix);

                SocketGuildChannel missioncategory = guild.GetChannel(MissionSettingsModel.MissionCategoryId);

                failcode++;
                // [01] Creating a temporary ulong list of explorerIds to generate a ping string
                List <ulong> explorerIDs = new List <ulong>();

                foreach (IUser user in explorers)
                {
                    explorerIDs.Add(user.Id);
                }
                string pingstring = ResourcesModel.GetMentionsFromUserIdList(explorerIDs);

                failcode++;

                // [02] Create new channel
                RestTextChannel NewMissionChannel = await guild.CreateTextChannelAsync(channelname);

                failcode++;

                // [03] Sync permissions with mission category
                foreach (Overwrite perm in missioncategory.PermissionOverwrites)
                {
                    if (perm.TargetType == PermissionTarget.Role)
                    {
                        IRole role = guild.GetRole(perm.TargetId);
                        await NewMissionChannel.AddPermissionOverwriteAsync(role, perm.Permissions);
                    }
                    else
                    {
                        IUser user = guild.GetUser(perm.TargetId);
                        await NewMissionChannel.AddPermissionOverwriteAsync(user, perm.Permissions);
                    }
                }

                failcode++;

                // [04] Add explorers  to mission room
                foreach (IUser user in explorers)
                {
                    await NewMissionChannel.AddPermissionOverwriteAsync(user, MissionSettingsModel.ExplorerPerms);
                }

                failcode++;

                // [05] Move to mission category and add channel topic
                string channeltopic;
                if (MissionSettingsModel.DefaultTopic.Contains("{0}"))
                {
                    channeltopic = string.Format(MissionSettingsModel.DefaultTopic, pingstring);
                }
                else
                {
                    channeltopic = MissionSettingsModel.DefaultTopic;
                }
                await NewMissionChannel.ModifyAsync(TextChannelProperties =>
                {
                    TextChannelProperties.CategoryId = MissionSettingsModel.MissionCategoryId;
                    TextChannelProperties.Topic      = channeltopic;
                });

                failcode++;

                // [06] Sending explorer questions
                EmbedBuilder embed = new EmbedBuilder();
                embed.Color = Var.BOTCOLOR;
                if (MissionSettingsModel.ExplorerQuestions.Contains("{0}"))
                {
                    embed.Description = string.Format(MissionSettingsModel.ExplorerQuestions, pingstring);
                }
                else
                {
                    embed.Description = MissionSettingsModel.ExplorerQuestions;
                }
                await NewMissionChannel.SendMessageAsync(pingstring, embed : embed.Build());

                failcode++;

                // [07] Sending debug message, adding to mission list and returning
                await SettingsModel.SendDebugMessage(string.Format("Created new mission room {0} on behalf of {1} for explorer {2}", NewMissionChannel.Mention, source.Mention, pingstring), DebugCategories.missions);

                missionList.Add(NewMissionChannel.Id);
                await SaveMissions();

                await MissionSettingsModel.SaveMissionSettings();

                return(NewMissionChannel);
            }
            catch (Exception e)
            {
                await SettingsModel.SendDebugMessage(string.Format("Creation of new mission channel failed. Failcode: {0}", failcode.ToString("X")), DebugCategories.missions);

                throw e;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Main Programs method running asynchronously
        /// </summary>
        /// <returns></returns>
        public async Task MainAsync()
        {
            Console.Title = "Ciridium Wing Bot v" + Var.VERSION.ToString();
            Thread.CurrentThread.CurrentCulture = Var.Culture;

            Var.client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel = LogSeverity.Info
            });

            bool filesExist = false;
            bool foundToken = false;

            if (ResourcesModel.CheckSettingsFilesExistence())
            {
                filesExist = true;
                if (await SettingsModel.LoadSettingsAndCheckToken(Var.client))
                {
                    foundToken = true;
                }
            }

            if (foundToken)
            {
                await MissionSettingsModel.LoadMissionSettings();

                await MissionModel.LoadMissions();

                await QuoteService.LoadQuotes();

                Var.client = new DiscordSocketClient(new DiscordSocketConfig
                {
                    LogLevel = LogSeverity.Info
                });

                InitCommands();

#if WELCOMING_MESSAGES
                Var.client.UserJoined += HandleUserJoined;
                Var.client.UserLeft   += HandleUserLeft;
#endif
                Var.client.Log             += Logger;
                SettingsModel.DebugMessage += Logger;
                Var.client.Connected       += ScheduleConnectDebugMessage;
                Var.client.ReactionAdded   += HandleReactionAdded;
                QuoteReactions quoteReact = new QuoteReactions();

                await Var.client.LoginAsync(TokenType.Bot, SettingsModel.token);

                await Var.client.StartAsync();

                await TimingThread.UpdateTimeActivity();

                while (Var.running)
                {
                    await Task.Delay(100);
                }

                if (string.IsNullOrEmpty(Var.RestartPath))
                {
                    await SettingsModel.SendDebugMessage("Shutting down ...", DebugCategories.misc);
                }
                else
                {
                    await SettingsModel.SendDebugMessage("Restarting ...", DebugCategories.misc);
                }

                Var.client.Dispose();
            }
            else
            {
                if (!filesExist)
                {
                    await Logger(new LogMessage(LogSeverity.Critical, "SETTINGS", string.Format("Could not find config files! Standard directory is \"{0}\".\nReply with 'y' if you want to generate basic files now!", ResourcesModel.BaseDirectory)));

                    if (Console.ReadLine().ToCharArray()[0] == 'y')
                    {
                        await ResourcesModel.InitiateBasicFiles();
                    }
                }
                else
                {
                    await Logger(new LogMessage(LogSeverity.Critical, "SETTINGS", string.Format("Could not find a valid token in Settings file ({0}). Press any key to exit!", ResourcesModel.SettingsFilePath)));

                    Console.ReadLine();
                }
            }

            if (!string.IsNullOrEmpty(Var.RestartPath))
            {
                System.Diagnostics.Process.Start(Var.RestartPath);
            }
        }