Exemplo n.º 1
0
 public static TwitchLib.Api.Models.v5.Users.User UserFromUserID(string UserID, int i = 0)
 {
     if (i == 10)
     {
         return(null);
     }
     try
     {
         Task <TwitchLib.Api.Models.v5.Users.User> GetUName = new TwitchLib.Api.Sections.Users.V5Api(Bot.TwitchA).GetUserByIDAsync(UserID);
         return(Task.Run(async() => await new TwitchLib.Api.Sections.Users.V5Api(Bot.TwitchA).GetUserByIDAsync(UserID)).Result);
     }
     catch (Exception E) { Console.WriteLine(E); return(UserFromUserID(UserID, i++)); }
 }
Exemplo n.º 2
0
        public void BotStart()
        {
            try
            {
                ConnectionCredentials credentials = new ConnectionCredentials("JustAnyBot", Settings.AuthToken);

                client = new TwitchClient();
                client.Initialize(credentials);
                client.OnConnected += Client_OnConnected;
                client.AddChatCommandIdentifier(char.Parse("#"));
                client.OnConnectionError += Client_ConnectionError;
                client.OnUserTimedout    += Client_TimedOut;
                if (Settings.AnnounceJoin)
                {
                    client.OnUserJoined += Client_UserJoined;
                }
                client.OnChatCommandReceived += Client_ChatCommandReceived;
                if (Settings.AnnounceLeave)
                {
                    client.OnUserLeft += Client_UserLeft;
                }
                if (Settings.ThankSubscribers)
                {
                    client.OnNewSubscriber += Client_Subscribed;
                }

                api = new TwitchAPI();
                api.Settings.ClientId    = Settings.ClientId;
                api.Settings.AccessToken = Settings.AuthToken;

                GetInfo();

                if (Settings.ThankFollowers)
                {
                    follower = new FollowerService(api, 5);
                    follower.SetChannelByChannelId(Settings.ChannelId);
                    follower.OnNewFollowersDetected += Client_Followed;
                    follower.StartService();
                }

                if (Settings.AnnounceBan)
                {
                    client.OnUserBanned += Client_Banned;
                }
                if (Settings.AnnounceNowHosting)
                {
                    client.OnNowHosting += Client_Hosting;
                }

                UserApi = new TwitchLib.Api.Sections.Users.V5Api(api);

                client.Connect();


                window.Dispatcher.Invoke((Action)(() =>
                {
                    window.BotStarting();
                }));
            }
            catch (ThreadAbortException e)
            {
                MessageBox.Show("Erro: A Janela fechou antes de obter o AuthToken");
            }
            catch (Exception e)
            {
                MessageBox.Show($"An exception has occurred: \n\n{e.Message}");
            }
        }