﻿using Kitsunebot.Events.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kitsunebot.Events
{
    public class Event_OnUserJoined : Event
    {
        protected Kitsunebot _bot;
        public override bool Add(Kitsunebot bot)
        {
            _bot = bot;
            bot.Client.OnUserJoined += Client_OnUserJoined;
            return true;
        }

        private void Client_OnUserJoined(object sender, TwitchLib.Events.Client.OnUserJoinedArgs e)
        {
            Channel.Channel channel = _bot.Channels.GetChannel(e.Channel);
            if (channel == null)
                return;

            channel.Users.Join(e.Username, false);

            channel.Engine.DoEvent(Name, new UserEventArgs { User = e.Username });
        }

        public override bool Remove(Kitsunebot bot)
        {
            bot.Client.OnUserJoined -= Client_OnUserJoined;
            return true;
        }
    }
}
