Exemple #1
0
        public async Task AddStream(string streamer)
        {
            Console.WriteLine("Executing add command for " + streamer);
            string        guildid   = Context.Guild.Id.ToString();
            string        guildpath = FileDirUtil.GetGuildDir(guildid);
            string        namepath  = Path.Combine(guildpath, FileDirUtil.JSONNAMES);
            List <string> names     = JSONUtil.GetJsonToList <string>(namepath);
            //"Link" can be twitch link or just the channel name
            string name = MessageUtil.GetChannelNameFromMessage(streamer);

            if (name == null)
            {
                await ReplyAsync("Invalid link, please check again");

                return;
            }
            if (!names.Contains(name))
            {
                names.Add(name);
                JSONUtil.WriteJsonToFile(names, namepath);
                await ReplyAsync("Successfully added streamer: " + name);

                //refresh IDS after adding
                await MessageUtil.GetChannelIDs(guildid, true);
            }
            else
            {
                await ReplyAsync("I already have that streamer stored, try !!list to check the current list");
            }
            await Context.Message.DeleteAsync();

            Console.WriteLine("leaving addstreamer");
        }
Exemple #2
0
        public async Task ChangePrefix(string newpref)
        {
            string   id            = Context.Guild.Id.ToString();
            string   settingsfile  = FileDirUtil.GetGuildFile(id, FileDirUtil.JSONSETTINGS);
            Settings guildsettings = JSONUtil.GetSettingsObj(id);   //get the settings for this guild

            guildsettings.prefix = newpref;

            JSONUtil.WriteJsonToFile(guildsettings, settingsfile);

            await ReplyAsync($"The prefix for the bot has been changed to **{newpref}**");
        }
Exemple #3
0
        private async Task JoinedGuild(SocketGuild guild)
        {
            Console.WriteLine("Entered guild ");
            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            Guilds guilds = JsonConvert.DeserializeObject <Guilds>(File.ReadAllText(FileDirUtil.JSONGUILDS), settings);//checks json containing all guilds + their settings

            Console.WriteLine("got guilds json");
            string id   = guild.Id.ToString();
            string name = guild.Name;

            List <string> ids = guilds.GetIds();

            Console.WriteLine("Entered guild " + name + " " + id);
            //if this is a brand new guild
            if ((guilds.guilds == null) || !ids.Contains(id))
            {
                string guildpath   = FileDirUtil.GetGuildDir(id);
                string settingfile = Path.Combine(guildpath, FileDirUtil.JSONSETTINGS);

                Console.WriteLine("new guild!");

                Settings gdst = new Settings("!!", id, 0);
                Console.WriteLine("settings!");

                Guild newguilld = new Guild(id, name, DateTime.Now, DateTime.Now);    //create the new guild with info
                Console.WriteLine("newguild!");

                guilds.AddGuild(newguilld);
                Console.WriteLine("addedguild!");

                await FileDirUtil.EstablishGuildFiles(newguilld);

                Console.WriteLine("writing guilds back to file");
                JSONUtil.WriteJsonToFile(guilds, FileDirUtil.JSONGUILDS);
                JSONUtil.WriteJsonToFile(gdst, settingfile);
                Console.WriteLine("completed setting up for new guild!");
            }
            else
            {
                Console.WriteLine("existing guild");
                await FileDirUtil.VerifyGuildFiles(id);
            }
            //write back the json
        }
Exemple #4
0
        public async Task AddReponse(string word, string reaction)
        {
            string   id            = Context.Guild.Id.ToString();
            string   settingsfile  = FileDirUtil.GetGuildFile(id, FileDirUtil.JSONSETTINGS);
            Settings guildsettings = JSONUtil.GetSettingsObj(id);

            bool addnew = guildsettings.AddOrModifyCommand(word.ToLower(), reaction);

            if (addnew)
            {
                await ReplyAsync($"Successfully added a new response for {word}!");
            }
            else
            {
                await ReplyAsync($"Successfully modified the response {word}");
            }

            JSONUtil.WriteJsonToFile(guildsettings, settingsfile);
        }
Exemple #5
0
        public async Task DeleteResponse(string word)
        {
            string   id            = Context.Guild.Id.ToString();
            string   settingsfile  = FileDirUtil.GetGuildFile(id, FileDirUtil.JSONSETTINGS);
            Settings guildsettings = JSONUtil.GetSettingsObj(id);

            bool remove = guildsettings.DelCommand(word.ToLower());

            if (remove)
            {
                await ReplyAsync($"Successfully deleted the response for {word}!");
            }
            else
            {
                await ReplyAsync($"Oops, looks like {word} didn't exist anyway!");
            }


            JSONUtil.WriteJsonToFile(guildsettings, settingsfile);
        }
Exemple #6
0
        public async Task CheckLive(SocketUserMessage msg, string guildid)
        {
            string guildids    = FileDirUtil.GetGuildFile(guildid, FileDirUtil.JSONIDS);
            string guildlive   = FileDirUtil.GetGuildFile(guildid, FileDirUtil.JSONLIVE);
            string guildstream = FileDirUtil.GetGuildFile(guildid, FileDirUtil.JSONSTREAMS);

            //dic of users to check; dic of last known live, list of currently live
            Dictionary <string, string> users = JSONUtil.GetJsonToDic <string, string>(guildids);
            Dictionary <string, string> live  = JSONUtil.GetJsonToDic <string, string>(guildlive);
            List <string> liveusers           = new List <string>();

            string s = string.Join("&channel=", users.Select(x => x.Value));

            string response = SendRequest(BaseString + "streams/?channel=", s, "Requesting live channels for " + s);

            Console.WriteLine("channelresponse" + response);
            JSONUtil.WriteJsonToFile(null, guildstream, response);

            Streams streams = JsonConvert.DeserializeObject <Streams>(response);

            //if any live streams, check if already noted as live, if not, set to "live" and notify
            if (streams._total > 0)
            {
                foreach (Stream x in streams.streams)
                {
                    liveusers.Add(x.channel.name);
                    if (live[x.channel.name] != "live")
                    {
                        live[x.channel.name] = "live";
                        SocketGuildUser guilduser = msg.Author as SocketGuildUser;
                        SocketRole      guildrole = guilduser.Guild.Roles.FirstOrDefault(y => y.Name == "notify");
                        string          mention   = "";
                        if (guildrole != null)
                        {
                            mention = guildrole.Mention;
                        }
                        await msg.Channel.SendMessageAsync($"{mention} {x.channel.name} has just gone live playing {x.channel.game}! \n" + "https://www.twitch.tv/" + x.channel.name);
                    }
                }
            }

            Console.WriteLine("check1");
            //check the current live against previous live
            //if set as live when not currently live, set to offline
            Dictionary <string, string> newDictionary = live.ToDictionary(entry => entry.Key,
                                                                          entry => entry.Value);

            Console.WriteLine("check2");
            foreach (KeyValuePair <string, string> entry in live)
            {
                if (entry.Value == "live")
                {
                    if (!liveusers.Any(x => x == entry.Key))
                    {
                        newDictionary[entry.Key] = "offline";
                    }
                }
            }
            Console.WriteLine("check3");
            live = newDictionary.ToDictionary(entry => entry.Key,
                                              entry => entry.Value);
            Console.WriteLine("check4");
            JSONUtil.WriteJsonToFile(live, guildlive);
            Console.WriteLine("Completed check\n");
        }