예제 #1
0
        public void Connect()
        {
            ConnectionCredentials credentials = new ConnectionCredentials(botName, accessToken);

            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };
            var customClient = new WebSocketClient(clientOptions);

            client = new TwitchClient(customClient);
            client.Initialize(credentials, channelName, '!');

            client.OnConnected       += Client_OnConnected;
            client.OnMessageReceived += Client_OnMessageReceived;

            client.Connect();

            Client_LoadContents();
        }
예제 #2
0
 public override void HandleMessage(ChatMessage chatMessage, TwitchClient twitchClient, Character activePlayer)
 {
     lock (messageHandlingLock)
     {
         string streamDeckCommand = StripCommandsFromMessage(chatMessage.Message, out string commands);
         foreach (IDungeonMasterCommand dungeonMasterCommand in Commands)
         {
             if (dungeonMasterCommand.Matches(streamDeckCommand))
             {
                 if (dungeonMasterCommand is SelectShortcutCommand shortcutCommand)
                 {
                     int playerId = DungeonMasterApp.GetPlayerIdFromName(shortcutCommand.playerInitial);
                     activePlayer = DungeonMasterApp.GetPlayerFromId(playerId);
                 }
                 Expressions.Do(commands, activePlayer);
                 dungeonMasterCommand.Execute(DungeonMasterApp, chatMessage);
                 return;
             }
         }
     }
 }
예제 #3
0
        private TwitchClient CreateClient(string aChannelName)
        {
            //Create a client from the array we get from the DB
            TwitchClient tc = new TwitchClient();

            tc.Initialize(m_Credentials, aChannelName);
            tc.ChatThrottler = new TwitchLib.Client.Services.MessageThrottler(tc, 20, TimeSpan.FromSeconds(30));
            tc.ChatThrottler.ApplyThrottlingToRawMessages = true;
            tc.ChatThrottler.StartQueue();

            //Setting listening events
            tc.OnLog             += Client_OnLog;
            tc.OnConnected       += Client_OnConnect;
            tc.OnConnectionError += Client_OnConnectionError;
            tc.OnMessageReceived += Client_OnMessageRecieved;
            tc.OnDisconnected    += Client_OnDisconnect;
            tc.OnWhisperReceived += Client_OnWhisperRecieved;
            tc.Connect();

            return(tc);
        }
예제 #4
0
        internal void Connect()
        {
            Console.WriteLine($"Letmebeyourbot v{System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()} by xeqlol\n");
            Console.WriteLine($"Connecting to {LetmebeyourbotInfo.ChannelName} channel...\n");

            TwitchAPI.Settings.ClientId = LetmebeyourbotInfo.ClientId;

            Credentials   = new ConnectionCredentials(LetmebeyourbotInfo.BotUsername, LetmebeyourbotInfo.BotToken);
            Client        = new TwitchClient(Credentials, LetmebeyourbotInfo.ChannelName, logging: true);
            MLimitHandler = new MessageLimitHandler();
            Channel       = TwitchAPI.Channels.v5.GetChannelByIDAsync(TwitchAPI.Users.v5.GetUserByNameAsync(LetmebeyourbotInfo.ChannelName).Result.Matches[0].Id).Result;

            // configure coin timer
            CoinTimer           = new Timer(1000 * 60 * 5);
            CoinTimer.Elapsed  += AddCoinsToChatters;
            CoinTimer.AutoReset = true;

            Client.OnConnectionError += Client_OnConnectionError;
            Client.OnMessageReceived += Client_OnMessageReceived;

            SetCommandHandler();

            try
            {
                Client.Connect();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Something goes wrong: {ex.Message}");
                return;
            }

            Console.WriteLine($"Connected to {LetmebeyourbotInfo.ChannelName} channel.");
            Console.WriteLine(!TwitchAPI.Streams.v5.BroadcasterOnlineAsync(Channel.Id.ToString()).Result
                ? "Status: offline"
                : $"Status: \tonline\nTitle: \t\t{Channel.Status}\nGame: \t\t{Channel.Game}\nUptimet: \t{TwitchAPI.Streams.v5.GetUptimeAsync(Channel.Id.ToString()).Result}");


            CoinTimer.Start();
        }
예제 #5
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            Creds  = new ConnectionCredentials(edtUser.Text, edtOauth.Text);
            Client = new TwitchClient(Creds, edtChannel.Text, '!', '!', true);

            Client.OnNewSubscriber   += OnNewSubscriber;
            Client.OnMessageReceived += OnMessageReceived;
            Client.OnMessageSent     += OnMessageSent;
            Client.OnUserBanned      += OnUserBanned;
            Client.OnUserTimedout    += OnUserTimedout;
            Client.OnLog             += OnLog;
            Client.OnIncorrectLogin  += OnIncorrectLogin;
            Client.OnNowHosting      += OnNowHosting;
            Client.OnHostingStarted  += OnHostingStarted;
            Client.OnHostingStopped  += OnHostingStopped;
            Client.Connect();
            Client.WillReplaceEmotes = true;
            btnConnect.Enabled       = false;
            btnDisconnect.Enabled    = true;
            edtMessage.Enabled       = true;
            btnSend.Enabled          = true;
            lbEmotes.Enabled         = true;
            btnSendEmotes.Enabled    = true;
            speCount.Enabled         = true;
            btnPower.Enabled         = true;
            btnPowerJ.Enabled        = true;
            btnPowerKursive.Enabled  = true;
            btnSend.Enabled          = true;
            edtMessage.Enabled       = true;

            edtUser.Enabled    = false;
            edtChannel.Enabled = false;
            edtOauth.Enabled   = false;

            //Channel ID
            C_ID             = GetID(edtChannel.Text);
            U_ID             = GetID(edtUser.Text);
            tmStream.Enabled = true;
            GetChannel(C_ID);
        }
예제 #6
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Logger.LogInformation("TwitchBot is starting.");

            string twitchUserName = Config["TwitchUsername"];
            string twitchToken    = Config["TwitchToken"];
            string twitchChannel  = Config["TwitchChannel"];


            ConnectionCredentials credentials = new ConnectionCredentials(twitchUserName, twitchToken);
            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };
            WebSocketClient customClient = new WebSocketClient(clientOptions);

            twitchClient = new TwitchClient(customClient);
            twitchClient.Initialize(credentials, twitchChannel);

            twitchClient.OnLog             += Client_OnLog;
            twitchClient.OnJoinedChannel   += Client_OnJoinedChannel;
            twitchClient.OnMessageReceived += Client_OnMessageReceived;
            twitchClient.OnWhisperReceived += Client_OnWhisperReceived;
            twitchClient.OnNewSubscriber   += Client_OnNewSubscriber;
            twitchClient.OnConnected       += Client_OnConnected;

            twitchClient.Connect();

            stoppingToken.Register(() => Logger.LogInformation("TwitchBot is stopping."));

            while (!stoppingToken.IsCancellationRequested)
            {
                Logger.LogInformation("TwitchBot is doing background work.");

                await Task.Delay(TimeSpan.FromSeconds(25), stoppingToken);
            }

            Logger.LogInformation("TwitchBot has stopped.");
        }
예제 #7
0
        private void ResetClient()
        {
            if (client != null)
            {
                client.OnConnected           -= Client_OnConnected;
                client.OnDisconnected        -= Client_OnDisconnected;
                client.OnChatCommandReceived -= Client_OnChatCommandReceived;
                client.OnMessageReceived     -= Client_OnMessageReceived;
                client.OnRaidNotification    -= Client_OnRaidNotification;
                client.OnBeingHosted         -= Client_OnBeingHosted;
                client.OnNewSubscriber       -= Client_OnNewSubscriber;
                //client.OnUserJoined -= Client_OnUserJoined;
                //client.OnUserLeft -= Client_OnUserLeft;
                client.OnConnectionError -= Client_OnConnectionError;
                client.OnError           -= Client_OnError;
            }
            client                        = null;
            client                        = new TwitchClient();
            client.OnConnected           += Client_OnConnected;
            client.OnDisconnected        += Client_OnDisconnected;
            client.OnChatCommandReceived += Client_OnChatCommandReceived;
            client.OnMessageReceived     += Client_OnMessageReceived;
            client.OnRaidNotification    += Client_OnRaidNotification;
            client.OnBeingHosted         += Client_OnBeingHosted;
            client.OnNewSubscriber       += Client_OnNewSubscriber;
            //client.OnUserJoined += Client_OnUserJoined;
            //client.OnUserLeft += Client_OnUserLeft;
            client.OnConnectionError += Client_OnConnectionError;
            client.OnError           += Client_OnError;

            // TODO -= these

            /*client.OnCommunitySubscription += Client_OnCommunitySubscription;
             * client.OnHostingStarted += Client_OnHostingStarted;
             * client.OnNewSubscriber += Client_OnNewSubscriber;
             * client.OnRaidNotification += Client_OnRaidNotification;
             * client.OnUserStateChanged += Client_OnUserStateChanged;
             * client.OnWhisperReceived += Client_OnWhisperReceived;
             */
        }
예제 #8
0
        public Bot()
        {
            BotName = "tmpName";
            ViewerRepository load = AssistantDb.Instance.Viewers;

            _viewersController = new ViewersController();

            try
            {
                ConnectionCredentials credentials;
                if (ConfigSet.Config.BotConfig.IsDualMode)
                {
                    BotName     = ConfigSet.Config.BotConfig.BotName;
                    credentials = new ConnectionCredentials(BotName, ConfigSet.Config.Auth.BotAuth.Tokens.AccessToken);
                    BotName     = "";
                }
                else
                {
                    credentials = new ConnectionCredentials(BotName, ConfigSet.Config.Auth.StreamerAuth.Tokens.AccessToken);
                    BotName     = "@" + ConfigSet.Config.BotConfig.BotName + " -> ";
                }
                Client = new TwitchClient();
                Client.Initialize(credentials, ConfigSet.Config.BotConfig.StreamName);
                Client.OnConnected       += Client_OnConnected;
                Client.OnConnectionError += Client_OnConnectedError;
                Client.OnDisconnected    += Client_onDisconnected;

                Client.OnUserJoined    += OnUserJoined;
                Client.OnUserLeft      += OnUserLeft;
                Client.OnNewSubscriber += OnNewSubscriber;

                Client.OnJoinedChannel   += OnJoinedChannel;
                Client.OnMessageReceived += OnMessageReceived;
                Client.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Bot constructor ex : incorrect bot name");
            }
        }
예제 #9
0
 private void metroButton1_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(tbx_channel.Text) && !string.IsNullOrEmpty(tbx_password.Text) && !string.IsNullOrEmpty(tbx_username.Text))
     {
         // neither one of the three may be empty
         username = tbx_username.Text;
         oauth    = tbx_password.Text;
         channel  = tbx_channel.Text;
         ConnectionCredentials cred = new ConnectionCredentials(username, oauth);
         if (client == null)
         {
             client = new TwitchClient(cred, channel, '!');
         }
         if (!client.IsConnected)
         {
             // connect pressed
             client.OnMessageReceived     += Client_OnMessageReceived;
             client.OnNewSubscriber       += Client_OnNewSubscriber;
             client.OnWhisperReceived     += Client_OnWhisperReceived;
             client.OnChatCommandReceived += Client_OnChatCommandReceived;
             client.OnConnected           += Client_OnConnected;
             client.OnConnectionError     += Client_OnConnectionError;
             client.OnUserJoined          += Client_OnUserJoined;
             client.OnUserLeft            += Client_OnUserLeft;
             client.OnUserTimedout        += Client_OnUserTimedout;
             client.OnUserBanned          += Client_OnUserBanned;
             client.Connect();
         }
         else
         {
             // disconnect pressed
             client.Disconnect();
             lbl_status.Style     = MetroFramework.MetroColorStyle.Red;
             lbl_status.Text      = "Disconnected";
             tbx_channel.Enabled  = true;
             tbx_username.Enabled = true;
             tbx_password.Enabled = true;
         }
     }
 }
예제 #10
0
        public static void BotConnect()
        {
            // Checks if twitch credentials are present
            if (string.IsNullOrEmpty(Settings.TwAcc) || string.IsNullOrEmpty(Settings.TwOAuth) || string.IsNullOrEmpty(Settings.TwChannel))
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    foreach (Window window in Application.Current.Windows)
                    {
                        if (window.GetType() == typeof(MainWindow))
                        {
                            //(window as MainWindow).icon_Twitch.Foreground = new SolidColorBrush(Colors.Red);
                            (window as MainWindow).LblStatus.Content = "Please fill in Twitch credentials.";
                        }
                    }
                }));
                return;
            }

            // creates new connection based on the credentials in settings
            ConnectionCredentials credentials   = new ConnectionCredentials(Settings.TwAcc, Settings.TwOAuth);
            ClientOptions         clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };
            WebSocketClient customClient = new WebSocketClient(clientOptions);

            _client = new TwitchClient(customClient);
            _client.Initialize(credentials, Settings.TwChannel);

            _client.OnMessageReceived += _client_OnMessageReceived;
            _client.OnConnected       += _client_OnConnected;
            _client.OnDisconnected    += _client_OnDisconnected;

            _client.Connect();

            // subscirbes to the cooldowntimer elapsed event for the command cooldown
            cooldownTimer.Elapsed += CooldownTimer_Elapsed;
        }
예제 #11
0
        private void startBot()
        {
            lock (lockObject)
            {
                if (!running)
                {
                    string configFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
                    using (StreamReader r = new StreamReader(configFilePath))
                    {
                        string json = r.ReadToEnd();
                        config = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
                    }

                    // The purpose of scrambling the token is mainly to prevent bots from scraping the token from GitHub.
                    // Please do not use this token for any other purpose than the normal functions of DrFujiBot. Thank you.
                    ConnectionCredentials credentials = new ConnectionCredentials("DrFujiBot", getToken());
                    var clientOptions = new ClientOptions
                    {
                        MessagesAllowedInPeriod = 750,
                        ThrottlingPeriod        = TimeSpan.FromSeconds(30)
                    };
                    TcpClient customClient = new TcpClient(clientOptions);
                    client = new TwitchClient(customClient);
                    client.Initialize(credentials, config["twitch_channel"]);

                    client.OnMessageReceived += Client_OnMessageReceived;
                    client.OnIncorrectLogin  += Client_OnIncorrectLogin;
                    client.OnConnectionError += Client_OnConnectionError;

                    client.Connect();

                    timer          = new Timer();
                    timer.Interval = 30000; // 30 seconds
                    timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
                    timer.Start();

                    running = true;
                }
            }
        }
예제 #12
0
        private async Task SetupTwitchClient()
        {
            var credentials =
                new ConnectionCredentials(_config[Constants.CONFIG_TWITCH_USERNAME],
                                          _config[Constants.CONFIG_TWITCH_PASSWORD]);
            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };

            var customClient = new WebSocketClient(clientOptions);

            _twitchClient = new TwitchClient(customClient);
            _twitchClient.Initialize(credentials);
            _twitchClient.AutoReListenOnException = true;

            _twitchClient.OnLog           += Client_OnLog;
            _twitchClient.OnJoinedChannel += Client_OnJoinedChannel;
            _twitchClient.OnConnected     += Client_OnConnected;
            _twitchClient.OnDisconnected  += Client_OnDisconnected;
            _twitchClient.OnLeftChannel   += async(s, e) => await Client_OnLeftChannel(s, e);

            _twitchClient.OnMessageReceived += async(s, e) => await Client_OnMessageReceived(s, e);

            _twitchClient.OnNewSubscriber += async(s, e) => await Client_OnNewSubscriber(s, e);

            _twitchClient.OnUserJoined += async(s, e) => await Client_OnUserJoined(s, e);

            _twitchClient.OnUserLeft += async(s, e) => await Client_OnUserLeft(s, e);

            _twitchClient.OnExistingUsersDetected += async(s, e) => await Client_OnExistingUsersDetected(s, e);

            _twitchClient.Connect();

            // TODO: Remove this as this is only for debug purposes
            _twitchClient.JoinChannel("cldubya");

            await Task.CompletedTask;
        }
예제 #13
0
        private bool SaveSettings()
        {
            var s = Program.settings;

            s.channelName = channelTextBox.Text;

            s.useStartMessage = useStartCheckBox.Checked;
            s.startMessage    = startTextBox.Text;
            s.useStopMessage  = useStopCheckBox.Checked;
            s.stopMessage     = stopTextBox.Text;
            s.noWinners       = noWinnersTextBox.Text;
            s.winnerPreamble  = winnerPreambleTextBox.Text;
            s.winner          = winnerTextBox.Text;
            s.showDoubled     = useDoubleCheckBox.Checked;
            s.doubledPreamble = doublePreambleTextBox.Text;
            s.doubled         = doubleTextBox.Text;

            //make sure these values are ok
            s.botName = usernameTextBox.Text;
            s.botPass = passTextBox.Text;
            try {
                ConnectionCredentials cred = new ConnectionCredentials(Program.settings.botName, Program.settings.botPass);
                var clientOptions          = new ClientOptions {
                    MessagesAllowedInPeriod = 750,
                    ThrottlingPeriod        = TimeSpan.FromSeconds(30)
                };
                WebSocketClient wsClient = new WebSocketClient(clientOptions);
                var             Client   = new TwitchClient(wsClient);
                Client.Initialize(cred, Program.settings.channelName);
            } catch (Exception) {
                MessageBox.Show("Error creating the Twitch connection. Please check your username and auth.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            Program.SaveSettings();
            Program.bot.Disconnect();
            Program.bot = new Bot();
            Program.mainWindow.InitBotListeners();
            return(true);
        }
예제 #14
0
파일: SGame.cs 프로젝트: LixYt/StreamHub
        public SGame(StreamConfig cfg)
        {
            InitializeComponent();

            #region Load Configuration
            cfg ??= new StreamConfig();
            config = cfg;
            #endregion

            #region Twitch
            client = new TwitchClient();

            try
            {
                var clientOptions = new ClientOptions
                {
                    MessagesAllowedInPeriod = 750,
                    ThrottlingPeriod        = TimeSpan.FromSeconds(30)
                };
                WebSocketClient customClient = new WebSocketClient(clientOptions);
                client = new TwitchClient(customClient);
                client.Initialize(config.GetCredential(), config.ChannelName);
                client.OnLog             += Client_OnLog;
                client.OnJoinedChannel   += Client_OnJoinedChannel;
                client.OnMessageReceived += Client_OnMessageReceived;
                client.OnWhisperReceived += Client_OnWhisperReceived;
                client.OnNewSubscriber   += Client_OnNewSubscriber;
                client.OnConnected       += Client_OnConnected;
                client.OnUserJoined      += Client_OnUserJoined;
                client.OnUserLeft        += Client_OnUserLeft;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            #endregion

            tabControl1.TabPages["tabConfig"].Select();
        }
예제 #15
0
        private void stopBot()
        {
            lock (lockObject)
            {
                if (running)
                {
                    if (null != client)
                    {
                        client.Disconnect();
                        client = null;
                    }

                    if (null != timer)
                    {
                        timer.Stop();
                        timer = null;
                    }

                    running = false;
                }
            }
        }
예제 #16
0
        public void Handle(TwitchClient client, ChatCommand command)
        {
            Debug.Log("!stats command used!");

            var playerManager = GameObject.FindObjectOfType <PlayerManager>();

            // Check if we are playing on a hosted stream, are hosting a stream or open world
            // * if we are playing on the open world stream, the current player's stats should be checked.
            // * if we are playing on a hosted stream, the current player's stats should be checked.
            // * if we are hosting a stream, the caller's player's stats should be checked

            var streamerName = client.Settings.TwitchChannel;
            var player       = playerManager.Me;

            if (!player)
            {
                client.SendChatMessage($"{streamerName} is not playing on any characters yet.");
                return;
            }

            client.SendChatMessage($"{streamerName} is playing {player.name} and its stats are: {GetSkillText(player)}");
        }
예제 #17
0
        public async void Process(TwitchClient client, string username, string commandText, bool isMod, JoinedChannel joinedChannel)
        {
            int.TryParse(commandText, out var numberOfTokens);
            if (numberOfTokens == 0)
            {
                numberOfTokens = 1;
            }
            var convertResponse = await _vipApiClient.ConvertBytes(new ConvertVipsRequest
            {
                Username      = username,
                NumberOfBytes = numberOfTokens
            });

            if (convertResponse == null)
            {
                client.SendMessage(joinedChannel,
                                   $"Hey @{username}, Sorry I can't do that at the moment, please try again in a few minutes");
                return;
            }

            client.SendMessage(joinedChannel, convertResponse.ConvertedBytes > 0 ? $"Hey @{username}, I've converted {convertResponse.ConvertedBytes} Byte(s) to VIP(s) :D" : $"Hey @{username}, it looks like you don't have enough byte(s) to do that. Stick around and you'll have enough in no time!");
        }
예제 #18
0
        public static IUnityContainer Create()
        {
            var container = new UnityContainer();
            var config    = ConfigHelper.GetConfig();

            var creds           = new ConnectionCredentials(config.ChatbotNick, config.ChatbotPass);
            var client          = new TwitchClient(creds, config.StreamerChannel);
            var api             = new TwitchAPI(accessToken: config.ChatbotAccessToken);
            var followerService = new FollowerService(api, 5);
            var pubsub          = new TwitchPubSub();

            container.RegisterInstance(api);
            container.RegisterInstance(client);
            container.RegisterInstance(followerService);
            container.RegisterInstance(pubsub);

            var commandHelper = new CommandHelper(container);

            container.RegisterInstance(commandHelper);

            return(container);
        }
예제 #19
0
        private void button1_Click(object sender, EventArgs e)
        {
            File.WriteAllText(chatFile, "");

            credentials = new ConnectionCredentials(textBox1.Lines[0], textBox2.Lines[0]);//https://twitchapps.com/tmi/
            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };

            customClient = new WebSocketClient(clientOptions);
            client       = new TwitchClient(customClient);
            client.Initialize(credentials, textBox1.Lines[0]);


            client.OnMessageReceived += Client_OnMessageReceived;


            client.Connect();
            Console.WriteLine("connected");
        }
예제 #20
0
        public Bot()
        {
            ConnectionCredentials credentials = new ConnectionCredentials(channelName, authToken);
            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };
            WebSocketClient customClient = new WebSocketClient(clientOptions);

            client = new TwitchClient(customClient);
            client.Initialize(credentials, channelName);

            client.OnLog             += Client_OnLog;
            client.OnJoinedChannel   += Client_OnJoinedChannel;
            client.OnMessageReceived += Client_OnMessageReceived;
            client.OnWhisperReceived += Client_OnWhisperReceived;
            client.OnNewSubscriber   += Client_OnNewSubscriber;
            client.OnConnected       += Client_OnConnected;

            client.Connect();
        }
예제 #21
0
 public static Dictionary <string, ICommand> GetCommands(TwitchClient client)
 {
     return(new Dictionary <string, ICommand>
     {
         { "alive", new CommandALive(client) },
         { "vector-say", new CommandSay(client) },
         { "vs", new CommandSay(client) },
         { "sfx", new CommandSFX(client) },
         { "vector-joke", new CommandTellJoke(client) },
         { "attention", new CommandAttention(client) },
         { "lurk", new CommandLurk(client) },
         { "unlurk", new CommandUnLurk(client) },
         { "commands", new CommandCommands(client) },
         { "scene", new CommandScene(client) },
         { "vector-bat", new CommandBat(client) },
         { "vector-vol", new CommandVol(client) },
         { "vector-move", new CommandMove(client) },
         { "vector-time", new CommandTime(client) },
         { "vector-play", new CommandPlay(client) },
         { "vector-whisper", new CommandWhisper(client) }
     });
 }
예제 #22
0
        private void ChatAndTrainer_Load(object sender, EventArgs e)
        {
            SafeAppendToChatBox("CONNECTING TO TWITCH CHAT\n");
            SafeAppendToChatBox(String.Format("NICK : {0}\n", NICK));
            SafeAppendToChatBox(String.Format("AUTH : {0}\n", AUTH));
            try
            {
                ConnectionCredentials login = new ConnectionCredentials(NICK, AUTH);

                client = new TwitchClient();
                client.Initialize(login, "saltybet");

                //twitch chat event fcuntions -- add more if needed?
                client.OnMessageReceived += onMessageReceived;
                //starts threaded client thing, chat event functions run on separate thread
                client.Connect();
            }
            catch
            {
                SafeAppendToChatBox("CONNECTION FAILED\n");
            }
        }
예제 #23
0
        public VoteBot(IOptions <TwitchInfo> options)
        {
            if (options is null)
            {
                throw new NullReferenceException();
            }

            _options = options.Value;

            var credentials = new ConnectionCredentials(_options.AccountName, _options.AccessToken);

            _client = new TwitchClient();
            _client.Initialize(credentials, _options.ChannelName);

            _client.OnLog           += OnLog;
            _client.OnJoinedChannel += OnJoinedChannel;
            _client.OnConnected     += OnConnected;

            _client.OnChatCommandReceived += HandleCommands;
            _client.OnLeftChannel         += OnLeftChannel;
            _client.Connect();
        }
예제 #24
0
        public void Process(TwitchClient client, string username, string commandText, bool isMod)
        {
            if (string.IsNullOrWhiteSpace(commandText))
            {
                client.SendMessage($"Hi @{username}, looks like you haven't included a request there!");
                return;
            }

            var(result, playlistPosition) = playlistHelper.AddRequest(username, commandText);
            if (result == AddRequestResult.PlaylistClosed)
            {
                client.SendMessage($"Hey @{username}, the playlist is currently closed. If you want to request a song still, try !vip");
            }
            else if (result == AddRequestResult.NoMultipleRequests)
            {
                client.SendMessage($"Hey @{username}, you can only have one non-vip request in the list!");
            }
            else
            {
                client.SendMessage($"Hey @{username}, I have queued {commandText} for you, you're #{playlistPosition} in the queue!");
            }
        }
예제 #25
0
        public static TwitchClient CreateNewClient(string channelName, string userName, string oauthPasswordName)
        {
            TwitchClient client     = new TwitchClient();
            var          oAuthToken = Configuration[$"Secrets:{oauthPasswordName}"];

            if (oAuthToken == null)
            {
                return(null);
            }
            var connectionCredentials = new ConnectionCredentials(userName, oAuthToken);

            client.Initialize(connectionCredentials, channelName);
            try
            {
                client.Connect();
                return(client);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #26
0
        private void SetupTwitchClient()
        {
            var credentials = new ConnectionCredentials(
                _config.GetSection("Twitch")["Username"],
                _config.GetSection("Twitch")["OAuth"]);

            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };

            var customClient = new WebSocketClient(clientOptions);

            client = new TwitchClient(customClient);
            client.Initialize(credentials, _config.GetSection("Twitch")["Username"]);

            client.OnMessageReceived += Client_OnMessageReceived;

            //client.OnChatCommandReceived += OnChatCommand;
            client.OnJoinedChannel += Client_OnJoinedChannel;
        }
예제 #27
0
        public void Init()
        {
            var credentials = new ConnectionCredentials(
                _config.Chat.BotName,
                _config.Chat.PasswordGeneratorToken);

            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30),
                ReconnectionPolicy      = new ReconnectionPolicy(1000)
            };

            var customClient = new WebSocketClient(clientOptions);

            Client = new TwitchClient(customClient);
            Client.Initialize(credentials, _config.Chat.Channel);

            Client.OnConnected     += ClientOnConnected;
            Client.OnDisconnected  += ClientOnDisconnected;
            Client.OnJoinedChannel += ClientOnJoinedChannel;
        }
            private void Connect()
            {
                var credentials   = new ConnectionCredentials(botUserName, authSettings.BotAccessToken, disableUsernameCheck: true);
                var clientOptions = new ClientOptions
                {
                    MessagesAllowedInPeriod = 750,
                    ThrottlingPeriod        = TimeSpan.FromSeconds(30)
                };
                var customClient = new WebSocketClient(clientOptions);

                client = new TwitchClient(customClient);
                client.Initialize(credentials, channel);

                client.OnLog             += Client_OnLog;
                client.OnJoinedChannel   += Client_OnJoinedChannel;
                client.OnMessageReceived += Client_OnMessageReceived;
                client.OnConnected       += Client_OnConnected;
                client.OnDisconnected    += Client_OnDisconnected;
                // client.OnWhisperReceived += Client_OnWhisperReceived;

                client.Connect();
            }
예제 #29
0
        private void InitializeClient()
        {
            var credentials = new ConnectionCredentials(
                _configuration.GetSection("twitch")["username"],
                _configuration.GetSection("twitch")["password"],
                _configuration.GetSection("twitch")["webSocketUri"],
                _configuration.GetSection("twitch").GetValue <bool>("disableUserNameCheck")
                );

            _client = new TwitchClient();

            _client.Initialize(credentials);

            _client.OnJoinedChannel += OnTwitchJoinChannel;
            _client.OnLeftChannel   += OnTwitchLeftChannel;

            _client.OnMessageReceived += OnTwitchMessage;
            _client.OnWhisperReceived += OnTwitchWhisperMessage;

            _client.OnChatCommandReceived    += OnTwitchCommand;
            _client.OnWhisperCommandReceived += OnTwitchWhisperCommand;

            _client.OnModeratorJoined += OnTwitchModeratorJoined;
            _client.OnModeratorLeft   += OnTwitchModeratorLeft;

            _client.OnUserJoined += OnTwitchUserJoined;
            _client.OnUserLeft   += OnTwitchUserLeft;

            _client.OnConnected += OnTwitchConnected;

            _client.AutoReListenOnException = true;
            _client.RemoveChatCommandIdentifier('!');
            _client.AddChatCommandIdentifier(_configuration.GetSection("twitch").GetSection("commandPrefix").Get <char>());

            _client.RemoveWhisperCommandIdentifier('!');
            _client.AddWhisperCommandIdentifier(_configuration.GetSection("twitch").GetSection("commandPrefix").Get <char>());

            _client.OnError += onTwitchError;
        }
예제 #30
0
        public async void Process(TwitchClient client, string username, string commandText, bool isMod, JoinedChannel joinedChannel)
        {
            var commandTerms = commandText.SplitCommandText();

            if (!int.TryParse(commandTerms[0], out var quoteId))
            {
                client.SendMessage(joinedChannel, $"Hey @{username}, looks like you didn't provide a Quote number for me to remove!");
                return;
            }

            var response = await _quoteApiClient.RemoveQuote(new RemoveQuoteRequest
            {
                QuoteId  = quoteId,
                Username = username,
                IsMod    = isMod
            });

            client.SendMessage(joinedChannel,
                               response
                    ? $"Hey @{username}, I have removed that quote for you!"
                    : $"Hey @{username}, I'm sorry I couldn't remove that quote. Is that one you created?");
        }
예제 #31
0
 public UserClient(TwitchClient client)
 {
     _client = client;
 }