Exemplo n.º 1
0
        public static async Task InitiateBasicFiles()
        {
            Directory.CreateDirectory(BaseDirectory);
            await SettingsModel.SaveSettings();

            await MissionSettingsModel.SaveMissionSettings();

            await MissionModel.SaveMissions();

            Directory.CreateDirectory(ShitpostingDirectory);
            Directory.CreateDirectory(QuotesDirectory);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        /// <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);
        }