示例#1
0
            // #### tasks ####

            static string MakeTimeoutJson(CommandContext ctx, DiscordMember member, string fileName)
            {
                var roles = member.Roles.ToArray();
                var json  = new TimeoutJson()
                {
                    RoleId        = new List <ulong>(),
                    CommandCaller = new CommandCaller {
                        DiscordId = ctx.Member.Id, Username = ctx.Member.Username
                    },
                    Victim = new Victim {
                        DiscordId = member.Id, Username = member.Username
                    },
                    HasBeenRestored = false
                };
                string filepath = $"Resources/RoleJSONs/{fileName}";

                if (roles.Length > 0)
                {
                    foreach (var role in roles)
                    {
                        json.RoleId.Add(role.Id);
                    }
                }

                string jsonString = JsonConvert.SerializeObject(json, Formatting.Indented);

                File.WriteAllText($"{filepath}", jsonString);

                return(fileName);
            }
示例#2
0
            static TimeoutJson GetTimeoutJson(string filePath)
            {
                var json = string.Empty;

                using (var fs = File.OpenRead($"Resources/RoleJSONs/{filePath}"))
                    using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                        json = sr.ReadToEnd();

                TimeoutJson timeoutJson = JsonConvert.DeserializeObject <TimeoutJson>(json);

                return(timeoutJson);
            }
示例#3
0
            void MarkTimeoutDone(string filePath)
            {
                var json = string.Empty;

                using (var fs = File.OpenRead($"Resources/RoleJSONs/{filePath}"))
                    using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                        json = sr.ReadToEnd();

                TimeoutJson timeoutJson = JsonConvert.DeserializeObject <TimeoutJson>(json);

                timeoutJson.HasBeenRestored = true;

                string jsonString = JsonConvert.SerializeObject(timeoutJson, Formatting.Indented);

                Console.WriteLine(jsonString);

                File.WriteAllText($"Resources/RoleJSONs/{filePath}", jsonString);
            }