Exemple #1
0
        public void Apply(IGuildConfig cfg)
        {
            //3.7 added a new portal channel. For guilds we update- make sure to set the portal channel, to the old war channel.
            cfg.SetGuildChannel(WarBotChannelType.PORTAL, cfg.GetGuildChannel(WarBotChannelType.WAR));

            //The new user notifications do not include the mention by default. Lets mimmick the setting.
            var uj = cfg[Setting_Key.USER_JOIN];

            if (uj.Enabled && uj.HasValue)
            {
                uj.Value = "{user}, " + uj.Value;
            }
        }
Exemple #2
0
        /// <summary>
        /// Sends an embed to the selected channel, if we have the proper permissions.
        /// Else- it will DM the owner of the guild.
        /// </summary>
        /// <param name="cfg"></param>
        /// <param name="embed"></param>
        ///
        /// <returns></returns>
        private static async Task sendWarMessage(IGuildConfig cfg, string Message)
        {
            SocketTextChannel ch = cfg.GetGuildChannel(WarBotChannelType.WAR) as SocketTextChannel;

            //If there is no channel configured, abort.
            if (ch == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(Message))
            {
                throw new NullReferenceException("War message is empty?");
            }

            //If we can send to the WAR channel, and we have permissions.
            if (PermissionHelper.TestBotPermission(ch, ChannelPermission.SendMessages))
            {
                await ch.SendMessageAsync(Message);

                return;
            }

            //Handle missing permissions below this line.
            await cfg.Log.Error(cfg.Guild, new Exception($"Missing SEND_PERMISSIONS for channel {ch.Name} for guild {cfg.Guild.Name}"));

            StringBuilder sb = new StringBuilder()
                               .AppendLine("ERROR: Missing Permissions")
                               .AppendLine($"You are receiving this error, because I do not have the proper permissions to send the war notification to channel {ch.Name}.")
                               .AppendLine("Please validate I have the 'SEND_MESSAGES' permission for the specified channel.");

            bool messageSent = await cfg.Log.MessageServerLeadership(cfg, sb.ToString());

            //If we were unsuccessful in delivaring a message to the guid's leadership, disable the message.
            if (!messageSent)
            {
                //Well, out of options. Lets disable this channel for the guild.
                cfg.SetGuildChannel(WarBotChannelType.WAR, null);
                await cfg.SaveConfig();

                UnauthorizedAccessException error = new UnauthorizedAccessException("Missing permissions to send to WAR Channel. WAR messages disabled for this guild.");
                await cfg.Log.Error(cfg.Guild, error, nameof(sendWarMessage));
            }
        }