public static async Task InitiateBasicFiles()
        {
            Directory.CreateDirectory(BaseDirectory);
            await SettingsModel.SaveSettings();

            await MissionSettingsModel.SaveMissionSettings();

            await MissionModel.SaveMissions();

            Directory.CreateDirectory(ShitpostingDirectory);
            Directory.CreateDirectory(QuotesDirectory);
        }
        private static async Task HandleTemplateCommand(CommandContext context)
        {
            bool   success = true;
            string message;

            switch (context.Args[2].ToLower())
            {
            case TEMPLATE_MISSIONCHANNELTOPIC:
                MissionSettingsModel.DefaultTopic = context.Message.Content.Substring(TEMPLATE_BASELENGTH + TEMPLATE_MISSIONCHANNELTOPIC.Length);
                message = "Successfully set mission channel default topic!";
                break;

            case TEMPLATE_EXPLORERQUESTIONS:
                MissionSettingsModel.ExplorerQuestions = context.Message.Content.Substring(TEMPLATE_BASELENGTH + TEMPLATE_EXPLORERQUESTIONS.Length);
                message = "Successfully set mission channel explorer questions!";
                break;

            case TEMPLATE_TESTIMONIALPROMPT:
                MissionSettingsModel.TestimonialPrompt = context.Message.Content.Substring(TEMPLATE_BASELENGTH + TEMPLATE_TESTIMONIALPROMPT.Length);
                message = "Successfully set mission channel testimonial prompt!";
                break;

            case TEMPLATE_FILEREPORTPROMPT:
                MissionSettingsModel.FileReportPrompt = context.Message.Content.Substring(TEMPLATE_BASELENGTH + TEMPLATE_FILEREPORTPROMPT.Length);
                message = "Successfully set mission channel report filing prompt!";
                break;

            default:
                message = "Could not recognise this template!";
                success = false;
                break;
            }
            if (success)
            {
                await MissionSettingsModel.SaveMissionSettings();
            }
            await context.Channel.SendEmbedAsync(message, !success);
        }
        private static async Task HandleMissionNumberCommand(CommandContext context)
        {
            string message = "";
            bool   error   = false;
            int    missionNr;

            if (int.TryParse(context.Args[2], out missionNr))
            {
                MissionSettingsModel.NextMissionNumber = missionNr;
                message = "Next missions number successfuly set to " + missionNr;
            }
            else
            {
                error   = true;
                message = "Could not parse supplied argument to a int32 value!";
            }
            if (!error)
            {
                await MissionSettingsModel.SaveMissionSettings();
            }

            await context.Channel.SendEmbedAsync(message, error);
        }
示例#4
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;
            }
        }
        /// <summary>
        /// handles the "/settings channel" command
        /// </summary>
        /// <param name="context"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        private static async Task HandleDefaultChannelCommand(CommandContext context)
        {
            string message   = "";
            bool   error     = false;
            ulong? channelId = null;

            if (ulong.TryParse(context.Args[3], out ulong Id))
            {
                channelId = Id;
            }
            else if (context.Message.MentionedChannels.Count > 0)
            {
                channelId = new List <SocketGuildChannel>(context.Message.MentionedChannels)[0].Id;
            }
            else if (context.Args[3].Equals("this"))
            {
                channelId = context.Channel.Id;
            }
            else
            {
                error   = true;
                message = "Cannot Parse the supplied Id as an uInt64 Value!";
            }

            if (channelId != null)
            {
                switch (context.Args[2])
                {
                case "debug":
                    SettingsModel.DebugMessageChannelId = (ulong)channelId;
                    await SettingsModel.SaveSettings();

                    message = "Debug channel successfully set to " + context.Guild.GetChannel((ulong)channelId).Name;
                    break;

                case "welcoming":
                    SettingsModel.WelcomeMessageChannelId = (ulong)channelId;
                    await SettingsModel.SaveSettings();

                    message = "Welcoming channel successfully set to " + context.Guild.GetChannel((ulong)channelId).Name;
                    break;

                case "missioncategory":
                    MissionSettingsModel.MissionCategoryId = (ulong)channelId;
                    await MissionSettingsModel.SaveMissionSettings();

                    message = "Mission category successfully set to " + context.Guild.GetChannel((ulong)channelId).Name;
                    break;

                default:
                    error   = true;
                    message = "I don't know that default channel!";
                    break;
                }
            }

            if (!error)
            {
                await SettingsModel.SaveSettings();
            }
            await context.Channel.SendEmbedAsync(message, error);
        }