Exemplo n.º 1
0
        public async Task Add(string channelName)
        {
            if (!IsApprovedAdmin)
            {
                return;
            }

            var twitchChannelId = await _twitchManager.GetTwitchIdByLogin(channelName);

            if (string.IsNullOrEmpty(twitchChannelId))
            {
                await Context.Channel.SendMessageAsync("Twitch Channel " + channelName + " does not exist.");

                return;
            }

            var file   = Constants.ConfigRootDirectory + Constants.GuildDirectory + Context.Guild.Id + ".json";
            var server = new DiscordServer();

            if (File.Exists(file))
            {
                server = JsonConvert.DeserializeObject <DiscordServer>(File.ReadAllText(file));
            }

            if (server.ServerTwitchChannels == null)
            {
                server.ServerTwitchChannels = new List <string>();
            }

            if (server.ServerTwitchChannelIds == null)
            {
                server.ServerTwitchChannelIds = new List <string>();
            }

            if (!string.IsNullOrEmpty(server.OwnerTwitchChannel) && server.OwnerTwitchChannel.ToLower().Equals(channelName.ToLower()))
            {
                await Context.Channel.SendMessageAsync("The channel " + channelName + " is configured as the Owner Twitch channel. " +
                                                       "Please remove it with the '!cb twitch resetowner' command and then try re-adding it.");

                return;
            }

            if (!server.ServerTwitchChannels.Contains(channelName.ToLower()))
            {
                server.ServerTwitchChannels.Add(channelName.ToLower());
                server.ServerTwitchChannelIds.Add(await _twitchManager.GetTwitchIdByLogin(channelName));
                await BotFiles.SaveDiscordServer(server, Context.Guild);

                await Context.Channel.SendMessageAsync("Added " + channelName + " to the server Twitch streamer list.");
            }
            else
            {
                await Context.Channel.SendMessageAsync(channelName + " is already on the server Twitch streamer list.");
            }
        }
Exemplo n.º 2
0
        public async Task Twitch(string channel)
        {
            string file = Constants.ConfigRootDirectory + Constants.UserDirectory + Context.Message.Author.Id + ".json";

            var user = new User();

            if (File.Exists(file))
            {
                user = JsonConvert.DeserializeObject <User>(File.ReadAllText(file));
            }

            user.Id         = Context.Message.Author.Id;
            user.TwitchName = channel;
            user.TwitchId   = await twitchManager.GetTwitchIdByLogin(user.TwitchName);

            File.WriteAllText(file, JsonConvert.SerializeObject(user));

            await Context.Channel.SendMessageAsync("Your Twitch channel has been set.");
        }
Exemplo n.º 3
0
        public async Task Twitch(string channel)
        {
            var user = ((IGuildUser)Context.Message.Author);

            if (!user.GuildPermissions.ManageGuild)
            {
                return;
            }

            var file   = Constants.ConfigRootDirectory + Constants.GuildDirectory + user.Guild.Id + ".json";
            var server = new DiscordServer();

            if (File.Exists(file))
            {
                server = JsonConvert.DeserializeObject <DiscordServer>(File.ReadAllText(file));
            }

            if (server.ServerTwitchChannels == null)
            {
                server.ServerTwitchChannels = new List <string>();
            }

            if (server.ServerTwitchChannelIds == null)
            {
                server.ServerTwitchChannelIds = new List <string>();
            }

            if (!server.ServerTwitchChannels.Contains(channel.ToLower()))
            {
                server.ServerTwitchChannels.Add(channel.ToLower());
                server.ServerTwitchChannelIds.Add(await twitchManager.GetTwitchIdByLogin(channel));
                File.WriteAllText(file, JsonConvert.SerializeObject(server));

                await Context.Channel.SendMessageAsync("Added " + channel + " to the server Twitch streamer list.");
            }
            else
            {
                await Context.Channel.SendMessageAsync(channel + " is already on the server Twitch streamer list.");
            }
        }
Exemplo n.º 4
0
        public async Task CanGetTwitchChannelId()
        {
            var response = await _twitchManager.GetTwitchIdByLogin(_testChannel);

            Assert.True(!string.IsNullOrEmpty(response));
        }