示例#1
0
        public TwitchBot(TwitchSettings settings, PokeTradeHub <PK8> hub)
        {
            Hub      = hub;
            Settings = settings;

            var credentials = new ConnectionCredentials(settings.Username, settings.Token);

            AutoLegalityWrapper.EnsureInitialized(Hub.Config.Legality);

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

            Channel = settings.Channel;
            WebSocketClient 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.OnWhisperReceived += Client_OnWhisperReceived;
            client.OnNewSubscriber   += Client_OnNewSubscriber;
            client.OnConnected       += Client_OnConnected;
            client.OnError           += (_, e) =>
                                        LogUtil.LogError(e.Exception.Message + Environment.NewLine + e.Exception.Message, "TwitchBot");
            client.OnConnectionError += (_, e) =>
                                        LogUtil.LogError(e.BotUsername + Environment.NewLine + e.Error.Message, "TwitchBot");

            client.Connect();
        }
示例#2
0
        public SysCord(PokeTradeHub <PK8> hub)
        {
            Hub = hub;
            SysCordInstance.Self    = this; // hack
            SysCordInstance.Manager = new DiscordManager(Hub.Config);
            AutoLegalityWrapper.EnsureInitialized(Hub.Config.Legality);

            _client = new DiscordSocketClient(new DiscordSocketConfig
            {
                // How much logging do you want to see?
                LogLevel = LogSeverity.Info,

                // If you or another service needs to do anything with messages
                // (eg. checking Reactions, checking the content of edited/deleted messages),
                // you must set the MessageCacheSize. You may adjust the number as needed.
                //MessageCacheSize = 50,
            });

            _commands = new CommandService(new CommandServiceConfig
            {
                // Again, log level:
                LogLevel = LogSeverity.Info,

                // There's a few more properties you can set,
                // for example, case-insensitive commands.
                CaseSensitiveCommands = false,
            });

            // Subscribe the logging handler to both the client and the CommandService.
            _client.Log   += Log;
            _commands.Log += Log;

            // Setup your DI container.
            _services = ConfigureServices();
        }
示例#3
0
        public TwitchBot(TwitchSettings settings, PokeTradeHub <PK8> hub)
        {
            Hub      = hub;
            Settings = settings;

            var credentials = new ConnectionCredentials(settings.Username, settings.Token);

            AutoLegalityWrapper.EnsureInitialized(Hub.Config.Legality);

            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = settings.ThrottleMessages,
                ThrottlingPeriod        = TimeSpan.FromSeconds(settings.ThrottleSeconds),
            };

            Channel = settings.Channel;
            WebSocketClient customClient = new WebSocketClient(clientOptions);

            client = new TwitchClient(customClient);

            var cmd = settings.CommandPrefix;

            client.Initialize(credentials, Channel, cmd, cmd);

            client.OnLog                    += Client_OnLog;
            client.OnJoinedChannel          += Client_OnJoinedChannel;
            client.OnMessageReceived        += Client_OnMessageReceived;
            client.OnWhisperReceived        += Client_OnWhisperReceived;
            client.OnChatCommandReceived    += Client_OnChatCommandReceived;
            client.OnWhisperCommandReceived += Client_OnWhisperCommandReceived;
            client.OnNewSubscriber          += Client_OnNewSubscriber;
            client.OnConnected              += Client_OnConnected;
            client.OnDisconnected           += Client_OnDisconnected;

            client.OnMessageThrottled += (_, e)
                                         => LogUtil.LogError($"Message Throttled: {e.Message}", "TwitchBot");
            client.OnWhisperThrottled += (_, e)
                                         => LogUtil.LogError($"Whisper Throttled: {e.Message}", "TwitchBot");

            client.OnError += (_, e) =>
                              LogUtil.LogError(e.Exception.Message + Environment.NewLine + e.Exception.StackTrace, "TwitchBot");
            client.OnConnectionError += (_, e) =>
                                        LogUtil.LogError(e.BotUsername + Environment.NewLine + e.Error.Message, "TwitchBot");

            client.Connect();

            if (settings.GenerateAssets)
            {
                AddAssetGeneration();
            }

            EchoUtil.Forwarders.Add(msg => client.SendMessage(Channel, msg));
            Hub.Queues.Forwarders.Add((bot, detail) => client.SendMessage(Channel, $"{bot.Connection.Name} is now trading (ID {detail.ID}) {detail.Trainer.TrainerName}"));
        }
示例#4
0
        public TwitchBot(TwitchSettings settings, PokeTradeHub <PK8> hub)
        {
            Hub      = hub;
            Settings = settings;

            var credentials = new ConnectionCredentials(settings.Username.ToLower(), settings.Token);

            AutoLegalityWrapper.EnsureInitialized(Hub.Config.Legality);

            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = settings.ThrottleMessages,
                ThrottlingPeriod        = TimeSpan.FromSeconds(settings.ThrottleSeconds),

                WhispersAllowedInPeriod = settings.ThrottleWhispers,
                WhisperThrottlingPeriod = TimeSpan.FromSeconds(settings.ThrottleWhispersSeconds),

                // message queue capacity is managed (10_000 for message & whisper separately)
                // message send interval is managed (50ms for each message sent)
            };

            Channel = settings.Channel;
            WebSocketClient customClient = new WebSocketClient(clientOptions);

            client = new TwitchClient(customClient);

            var cmd = settings.CommandPrefix;

            client.Initialize(credentials, Channel, cmd, cmd);

            client.OnLog                    += Client_OnLog;
            client.OnJoinedChannel          += Client_OnJoinedChannel;
            client.OnMessageReceived        += Client_OnMessageReceived;
            client.OnWhisperReceived        += Client_OnWhisperReceived;
            client.OnChatCommandReceived    += Client_OnChatCommandReceived;
            client.OnWhisperCommandReceived += Client_OnWhisperCommandReceived;
            client.OnNewSubscriber          += Client_OnNewSubscriber;
            client.OnConnected              += Client_OnConnected;
            client.OnDisconnected           += Client_OnDisconnected;
            client.OnLeftChannel            += Client_OnLeftChannel;

            client.OnMessageSent += (_, e)
                                    => LogUtil.LogText($"{client.TwitchUsername}] - Message Sent in {e.SentMessage.Channel}: {e.SentMessage.Message}");
            client.OnWhisperSent += (_, e)
                                    => LogUtil.LogText($"{client.TwitchUsername}] - Whisper Sent to @{e.Receiver}: {e.Message}");

            client.OnMessageThrottled += (_, e)
                                         => LogUtil.LogError($"Message Throttled: {e.Message}", "TwitchBot");
            client.OnWhisperThrottled += (_, e)
                                         => LogUtil.LogError($"Whisper Throttled: {e.Message}", "TwitchBot");

            client.OnError += (_, e) =>
                              LogUtil.LogError(e.Exception.Message + Environment.NewLine + e.Exception.StackTrace, "TwitchBot");
            client.OnConnectionError += (_, e) =>
                                        LogUtil.LogError(e.BotUsername + Environment.NewLine + e.Error.Message, "TwitchBot");

            client.Connect();

            if (client.JoinedChannels.Count == 0)
            {
                client.JoinChannel(Channel);
            }

            EchoUtil.Forwarders.Add(msg => client.SendMessage(Channel, msg));

            // Turn on if verified
            // Hub.Queues.Forwarders.Add((bot, detail) => client.SendMessage(Channel, $"{bot.Connection.Name} is now trading (ID {detail.ID}) {detail.Trainer.TrainerName}"));
        }