Beispiel #1
0
        [RequirePermissions(Permissions.BanMembers)] // and restrict this to users who have appropriate permissions
        public async Task Edit(CommandContext ctx, [Description("lien vers l'image de la prog")] string newProg)
        {
            ProgJson url = LoadConfig();
            await ctx.TriggerTypingAsync();

            url.Prog = newProg;
            // wrap it into an embed
            await SaveConfig(url);

            await ctx.RespondAsync("Programmation mise à jour");
        }
Beispiel #2
0
        private Task SaveConfig(ProgJson cfgjson)
        {
            // first, let's load our configuration file

            //write string to file
            //await File.OpenWrite("configMAL.json");
            using (StreamWriter file = File.CreateText("prog.json"))
            {
                JsonSerializer serializer = new JsonSerializer();
                //serialize object directly into file stream
                serializer.Serialize(file, cfgjson);
            }
            // next, let's load the values from that file
            // to our client's configuration
            //var cfgjson = JsonConvert.DeserializeObject<ConfigMAL>(json);
            return(Task.CompletedTask);
        }
Beispiel #3
0
        // commands in this group need to be executed as
        // <prefix>memes [command] or <prefix>copypasta [command]

        // this is the group's command; unlike with other commands,
        // any attributes on this one are ignored, but like other
        // commands, it can take arguments
        public async Task ExecuteGroupAsync(CommandContext ctx)
        {
            ProgJson url   = LoadConfig();
            var      embed = new DiscordEmbedBuilder
            {
                Title = "Programation",
                Url   = "http://zerator.com/programmation",
            };

            if (url.Prog != "")
            {
                embed.ImageUrl = url.Prog;
            }
            else
            {
                embed.Description = "Programmation non disponible";
            }
            await ctx.RespondAsync(embed : embed);
        }
Beispiel #4
0
        public static async Task RunBotAsync()
        {
            Console.Title = "Zerator Discord";

            var    cfg = JsonConfig.Instance.Data;
            string json;

            if (!File.Exists("prog.json"))
            {
                var cfgProg = new ProgJson();
                json = JsonConvert.SerializeObject(cfgProg);
                File.WriteAllText("prog.json", json, new UTF8Encoding(false));
                Console.WriteLine("prog file was not found, a new one was generated.");
            }

            if (!File.Exists("configMAL.json"))
            {
                var cfgTwitch = new Dictionary <string, string>(new Dictionary <string, string>());;
                json = JsonConvert.SerializeObject(cfgTwitch);
                File.WriteAllText("configMAL.json", json, new UTF8Encoding(false));
                Console.WriteLine("configMAL file was not found, a new one was generated.");
            }


            var tskl = new List <Task>();

            for (var i = 0; i < cfg.ShardCount; i++)
            {
                var bot = new Bot(cfg, i);
                Shards.Add(bot);
                tskl.Add(bot.RunAsync());
                await Task.Delay(7500).ConfigureAwait(false);
            }

            await Task.WhenAll(tskl).ConfigureAwait(false);

            try
            {
                await Task.Delay(-1, CancelToken).ConfigureAwait(false);
            }
            catch (Exception) { /* shush */ }
        }
Beispiel #5
0
        public static async Task RunBotAsync()
        {
            Console.Title = "Zerator Discord";

            var    cfg = new ConfigJson();
            string json;

            if (!File.Exists("config.json"))
            {
                json = JsonConvert.SerializeObject(cfg);
                File.WriteAllText("config.json", json, new UTF8Encoding(false));
                Console.WriteLine("Config file was not found, a new one was generated. Fill it with proper values and rerun this program");
                Console.ReadKey();

                return;
            }
            if (!File.Exists("member.json"))
            {
                var cfgProg = new ListMembers();
                json = JsonConvert.SerializeObject(cfgProg);
                File.WriteAllText("member.json", json, new UTF8Encoding(false));
                Console.WriteLine("member file was not found, a new one was generated.");
            }
            if (!File.Exists("prog.json"))
            {
                var cfgProg = new ProgJson();
                json = JsonConvert.SerializeObject(cfgProg);
                File.WriteAllText("prog.json", json, new UTF8Encoding(false));
                Console.WriteLine("prog file was not found, a new one was generated.");
            }
            if (!File.Exists("twitch.json"))
            {
                var cfgTwitch = new StreamerStatus();
                json = JsonConvert.SerializeObject(cfgTwitch);
                File.WriteAllText("twitch.json", json, new UTF8Encoding(false));
                Console.WriteLine("twitch file was not found, a new one was generated.");
            }
            if (!File.Exists("configMAL.json"))
            {
                var cfgTwitch = new Dictionary <string, string>(new Dictionary <string, string>());;
                json = JsonConvert.SerializeObject(cfgTwitch);
                File.WriteAllText("configMAL.json", json, new UTF8Encoding(false));
                Console.WriteLine("configMAL file was not found, a new one was generated.");
            }
            json = File.ReadAllText("config.json", new UTF8Encoding(false));
            cfg  = JsonConvert.DeserializeObject <ConfigJson>(json);


            var tskl = new List <Task>();

            for (var i = 0; i < cfg.ShardCount; i++)
            {
                var bot = new Bot(cfg, i);
                Shards.Add(bot);
                tskl.Add(bot.RunAsync());
                await Task.Delay(7500).ConfigureAwait(false);
            }

            await Task.WhenAll(tskl).ConfigureAwait(false);

            try
            {
                await Task.Delay(-1, CancelToken).ConfigureAwait(false);
            }
            catch (Exception) { /* shush */ }
        }