コード例 #1
0
        public async Task ClearWarning(IGuildUser user)
        {
            // Create a target of type SocketGuild so we can retreive information from the GuildProfiles
            SocketGuild target = null;

            target = Context.Guild;

            string guildId = Context.Guild.Id.ToString();        // Guild ID

            string warnFolder = "Resources";                     // Folder to place the warnFile inside of
            string warnFile   = $"{guildId}warn.json";           // Warning file : guildId + warn.json

            var guildProfile = GuildProfiles.GetAccount(target); // Guild Profile

            if (!Directory.Exists(warnFolder))
            {
                Directory.CreateDirectory(warnFolder);
            }
            // warnFile does not exist, create it and add in the userId and 1 warning to the user.
            // If warnFile does exist, load the user's warnings and and 1 warning to the existing warning.
            if (!File.Exists(warnFolder + "/" + warnFile))
            {
                conf.UserId           = user.Id;
                conf.NumberOfWarnings = 0;
                conf.WarningMessage   = "";
                conf.UserUsername     = user.Username;
                conf.ModUsername      = Context.User.Username;

                string json = JsonConvert.SerializeObject(conf, Formatting.Indented);
                File.WriteAllText(warnFolder + "/" + warnFile, json);
            }
            else
            {
                ulong currentGuild = Context.Guild.Id;

                string json = File.ReadAllText(warnFolder + "/" + warnFile);
                conf = JsonConvert.DeserializeObject <WarnConfig>(json);

                conf.UserId = user.Id;
                if (conf.NumberOfWarnings <= 0)
                {
                    conf.NumberOfWarnings = 0;
                }
                else
                {
                    conf.NumberOfWarnings--;
                }
                conf.WarningMessage = "";
                conf.UserUsername   = user.Username;
                conf.ModUsername    = Context.User.Username;

                string json1 = JsonConvert.SerializeObject(conf, Formatting.Indented);
                File.WriteAllText(warnFolder + "/" + warnFile, json1);
            }

            await Context.Channel.SendMessageAsync($":white_check_mark: {user.Username}#{user.Discriminator} warning has been cleared. He now has {conf.NumberOfWarnings} warning(s).");
        }
コード例 #2
0
        public async Task WarnUser(IGuildUser user, [Remainder] string reason = "No Reason")
        {
            // Create a target of type SocketGuild so we can retreive information from the GuildProfiles
            SocketGuild target = null;

            target = Context.Guild;

            string guildId = Context.Guild.Id.ToString();        // Guild ID

            string warnFolder = "Resources";                     // Folder to place the warnFile inside of
            string warnFile   = $"{guildId}warn.json";           // Warning file : guildId + warn.json

            var guildProfile = GuildProfiles.GetAccount(target); // Guild Profile


            if (!Directory.Exists(warnFolder))
            {
                Directory.CreateDirectory(warnFolder);
            }
            // warnFile does not exist, create it and add in the userId and 1 warning to the user.
            // If warnFile does exist, load the user's warnings and and 1 warning to the existing warning.
            if (!File.Exists(warnFolder + "/" + warnFile))
            {
                conf.UserId           = user.Id;
                conf.NumberOfWarnings = 1;
                conf.WarningMessage   = reason;
                conf.UserUsername     = user.Username;
                conf.ModUsername      = Context.User.Username;

                string json = JsonConvert.SerializeObject(conf, Formatting.Indented);
                File.WriteAllText(warnFolder + "/" + warnFile, json);
            }
            else
            {
                ulong currentGuild = Context.Guild.Id;

                string json = File.ReadAllText(warnFolder + "/" + warnFile);
                conf = JsonConvert.DeserializeObject <WarnConfig>(json);

                conf.UserId = user.Id;
                conf.NumberOfWarnings++;
                conf.WarningMessage = reason;
                conf.UserUsername   = user.Username;
                conf.ModUsername    = Context.User.Username;

                string json1 = JsonConvert.SerializeObject(conf, Formatting.Indented);
                File.WriteAllText(warnFolder + "/" + warnFile, json1);
            }

            var dmChannel = await user.GetOrCreateDMChannelAsync();

            await dmChannel.SendMessageAsync($"You have been warned in **{Context.Guild.Name}** with the reason:\n\n **{reason}**\n\n This makes {conf.NumberOfWarnings} warning(s).");

            await Context.Channel.SendMessageAsync($":white_check_mark: {user.Username}#{user.Discriminator} has been warned.");

            // Check warnings
            if (conf.NumberOfWarnings == guildProfile.NumberofWarnings)
            {
                if (guildProfile.WarningsBan)
                {
                    await dmChannel.SendMessageAsync($"You have been banned from **{Context.Guild.Name}** with the reason:\n\n Warned **{conf.NumberOfWarnings}** time(s)");

                    await user.Guild.AddBanAsync(user, 7, $"Banned for having {guildProfile.NumberofWarnings} warning(s)");

                    conf.NumberOfWarnings = 0;
                }
                else if (guildProfile.WarningsKick)
                {
                    await dmChannel.SendMessageAsync($"You have been kicked from **{Context.Guild.Name}** with the reason:\n\n Warned **{conf.NumberOfWarnings}** time(s)");

                    await user.KickAsync("reason");

                    conf.NumberOfWarnings = 0;
                }
                else if (guildProfile.WarningsMute)
                {
                    // Mute
                }
                else
                {
                }
            }

            string json2 = JsonConvert.SerializeObject(conf, Formatting.Indented);

            File.WriteAllText(warnFolder + "/" + warnFile, json2);
        }