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(); }
private void AddTwitchBot(TwitchSettings config) { if (string.IsNullOrWhiteSpace(config.Token)) { return; } if (Twitch != null) { return; // already created } if (string.IsNullOrWhiteSpace(config.Channel)) { return; } if (string.IsNullOrWhiteSpace(config.Username)) { return; } if (string.IsNullOrWhiteSpace(config.Token)) { return; } Twitch = new TwitchBot <T>(config, Hub); if (config.DistributionCountDown) { Hub.BotSync.BarrierReleasingActions.Add(() => Twitch.StartingDistribution(config.MessageStart)); } }
public TwitchChatService( TwitchSettings twitchSettings, HubConnection connection) { _settings = twitchSettings; _connection = connection; _connection.StartAsync(); ConnectionCredentials connectionCredentials = new ConnectionCredentials(_settings.Channel, _settings.AuthToken); var clientOptions = new ClientOptions { MessagesAllowedInPeriod = 750, ThrottlingPeriod = TimeSpan.FromSeconds(30) }; WebSocketClient webSocketClient = new WebSocketClient(clientOptions); _client = new TwitchClient(webSocketClient); _client.Initialize(connectionCredentials, "LuceCarter"); _client.OnLog += TwitchClient_OnLog; _client.OnJoinedChannel += TwitchClient_OnJoinedChannel; _client.OnMessageReceived += TwitchClient_OnMessageReceived; _client.OnConnected += TwitchClient_OnConnected; _client.Connect(); }
public Bot(TwitchSettings twitchSettings, IServiceProvider serviceProvider, ILoggingService loggingService) { this.serviceProvider = serviceProvider; this.loggingService = loggingService; LoadCommands(); ConnectionCredentials credentials = new ConnectionCredentials("developersgarage_bot", twitchSettings.OauthToken); var clientOptions = new ClientOptions { MessagesAllowedInPeriod = 750, ThrottlingPeriod = TimeSpan.FromSeconds(30) }; WebSocketClient customClient = new WebSocketClient(clientOptions); client = new TwitchClient(customClient); client.Initialize(credentials, "developersgarage"); 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.Connect(); }
public TwitchBot(TwitchSettings settings, PokeTradeHub <PK8> hub) { Hub = hub; Settings = settings; var credentials = new ConnectionCredentials(settings.Username.ToLower(), settings.Token); 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.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(); 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}")); }
public TwitchClientService( TwitchSettings settings, HubConnection connection, TrelloService trelloService) { _settings = settings; _connection = connection; _trelloService = trelloService; _connection.StartAsync(); ConnectionCredentials credentials = new ConnectionCredentials(_settings.BotName, _settings.AuthToken); var clientOptions = new ClientOptions { MessagesAllowedInPeriod = 750, ThrottlingPeriod = TimeSpan.FromSeconds(30) }; WebSocketClient customClient = new WebSocketClient(clientOptions); _client = new TwitchClient(customClient); _client.Initialize(credentials, _settings.Channel); _client.OnLog += Client_OnLog; _client.OnJoinedChannel += Client_OnJoinedChannel; _client.OnChatCommandReceived += Client_OnCommandReceived; _client.OnWhisperReceived += Client_OnWhisperReceived; _client.OnRaidNotification += Client_OnRaidNotification; _client.OnNewSubscriber += Client_OnNewSubscriber; _client.OnGiftedSubscription += Client_OnGiftSubscriber; _client.OnConnected += Client_OnConnected; _client.Connect(); }
public TwitchUserService(IMemoryCache cache, IDbContextFactory <TwitchEbooksContext> contextFactory, TwitchApiFactory apiFactory, TwitchSettings settings) { _cache = cache; _contextFactory = contextFactory; _apiFactory = apiFactory; _settings = settings; }
public TwitchSettings GeTwitchSettings() { var twitchSettings = new TwitchSettings(); _configuration.GetSection("Twitch").Bind(twitchSettings); return(twitchSettings); }
public TwitchChatClient(TwitchSettings settings) { reChatMessage = new Regex($@"PRIVMSG #{chatChannelName} :(.*)$"); reWhisperMessage = new Regex($@"WHISPER {chatBotName} :(.*)$"); oauthToken = settings.OauthToken; _Shutdown = new CancellationTokenSource(); }
public static void AddTwitchAPI(this IServiceCollection collection, TwitchSettings twitchSettings) { var api = new TwitchAPI(); api.Settings.AccessToken = twitchSettings.OauthToken; api.Settings.ClientId = twitchSettings.ClientId; collection.AddSingleton(api); }
private void generalToolStripMenuItem_Click(object sender, EventArgs e2) { SettingsForm a = new SettingsForm(); a.saved += (o, e) => { generalSettings = TwitchSettings.Interpret(JsonConvert.DeserializeObject <dynamic>(File.ReadAllText("settings.json"))); }; a.Show(); }
public TwitchPubSubService( IOptionsMonitor <TwitchSettings> optionsMonitor, IServiceProvider provider, ILogger <TwitchPubSubService> logger) { _provider = provider; _logger = logger; _twitchSettings = optionsMonitor.CurrentValue; _pubsub = new(); }
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}")); }
public RefreshTokensRequestHandler( ILogger <RefreshTokensRequestHandler> logger, IDbContextFactory <TwitchEbooksContext> contextFactory, TwitchApi twitchApi, TwitchSettings settings) { _logger = logger; _contextFactory = contextFactory; _twitchApi = twitchApi; _settings = settings; }
public TwitchApiService(TwitchSettings settings, HubConnection connection) { _settings = settings; API = new TwitchAPI(); API.Settings.ClientId = _settings.ClientId; API.Settings.AccessToken = _settings.ChannelAuthToken; _connection = connection; _connection.StartAsync(); //Task.Run(() => ConfigLiveMonitorAsync()); }
public TwitchTradeNotifier(T data, PokeTradeTrainerInfo info, int code, string username, TwitchClient client, string channel, TwitchSettings settings) { Data = data; Info = info; Code = code; Username = username; Client = client; Channel = channel; Settings = settings; LogUtil.LogText($"Created trade details for {Username} - {Code}"); }
public TwitchSettingsViewModel() { MessengerInstance.Register <NotificationMessage>(this, (m) => Save(m)); if (Configuration.Instance.Stream is TwitchSettings) { TwitchSettings s = Configuration.Instance.Stream as TwitchSettings; ChannelName = s.ChannelName; OAuthToken = s.OAuthToken; } CheckChannelCommand = new RelayCommand(() => CheckChannel()); GetTokenCommand = new RelayCommand(() => GetToken()); }
public ChatViewModel(TwitchService twitchService, TwitchSettings twitchSettings, IPhoneticMatch phonetic, ToolContext context, OverrustlelogsService overrustlelogsService) { Messages = new ObservableCollection <TwitchMessage>(); _twitchService = twitchService; TwitchSettings = twitchSettings; _phonetic = phonetic; _context = context; _overrustlelogsService = overrustlelogsService; _twitchService.Client.OnMessageReceived += Client_OnMessageReceived; _whitelistedWords = _context.WhitelistWords.ToList(); _whitelistedUsers = _context.WhitelistUsers.ToList(); }
public TwitchService( ILogger <TwitchService> logger, IDbContextFactory <TwitchEbooksContext> contextFactory, IMediator mediator, ITwitchUserService userService, TwitchApiFactory apiFactory, TwitchClient client, TwitchSettings settings) { _logger = logger; _contextFactory = contextFactory; _mediator = mediator; _userService = userService; _apiFactory = apiFactory; _client = client; _settings = settings; }
public static IServiceCollection AddTwitchSettings(this IServiceCollection services, IConfiguration Configuration) { var ts = new TwitchSettings(); //ts.Username = (string)Configuration.GetValue(typeof(string), "TwitchSettings:Username"); //ts.Token = (string)Configuration.GetValue(typeof(string), "TwitchSettings:Token"); ts.ClientId = (string)Configuration.GetValue(typeof(string), "TwitchSettings:ClientId"); ts.ClientSecret = (string)Configuration.GetValue(typeof(string), "TwitchSettings:ClientSecret"); if (string.IsNullOrEmpty(ts.ClientId) || string.IsNullOrEmpty(ts.ClientSecret)) //|| string.IsNullOrEmpty(ts.ClientId)||string.IsNullOrEmpty(ts.ClientSecret) string.IsNullOrEmpty(ts.Username) || string.IsNullOrEmpty(ts.Token) { throw new ArgumentNullException("Check configuration settings for Twitch ClientId or ClientSecret"); } services.AddSingleton(ts); return(services); }
public TwitchPubSubService( TwitchSettings settings, HubConnection connection) { _settings = settings; _connection = connection; _connection.StartAsync(); _client = new TwitchPubSub(); _client.OnPubSubServiceConnected += onPubSubServiceConnected; _client.OnListenResponse += onListenResponse; _client.OnStreamUp += onStreamUp; _client.OnStreamDown += onStreamDown; _client.OnRewardRedeemed += onRewardRedeemed; _client.OnFollow += onFollow; _client.ListenToFollows(_settings.ChannelId); _client.ListenToRewards(_settings.ChannelId); _client.Connect(); }
public MainForm() { InitializeComponent(); CheckGeneralSettings(); //Emojis.Init(); generalSettings = TwitchSettings.Interpret(JsonConvert.DeserializeObject <dynamic>(File.ReadAllText("settings.json"))); if (Directory.Exists("./.AutoUpdater")) { string fileName = "./.AutoUpdater/AutoUpdater.exe"; File.Delete("./AutoUpdater.exe"); File.Copy(fileName, "./AutoUpdater.exe"); File.Delete(fileName); Directory.Delete("./.AutoUpdater"); MessageBox.Show("Update Complete!"); } new Thread(() => { Emojis.codeToEmoji.ToString(); }).Start(); #if !DEBUG using (WebClient client = new WebClient()) { string v = ""; try { v = client.DownloadString("http://blog.detolly.no/version.txt"); } catch { v = version; MessageBox.Show("Internet connection not present. Please connect to the internet to use this application."); } if (v != version) { DialogResult result = MessageBox.Show("New update available. \nNew update version: " + v + "\n Want to update?", "Update", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Process.Start("AutoUpdater.exe", "--url=\"http://blog.detolly.no/TwitchChat-" + v + ".zip"); Process.GetCurrentProcess().Kill(); } } } #endif Fontlabel.Text = defaultFont.Name + ", " + defaultFont.Size; radios = new RadioButton[] { radioButton1, radioButton2, radioButton3, radioButton4, radioButton5, radioButton6 }; amountOfThings = radios.Length; chatFormSettings = new ChatFormSettings[amountOfThings]; for (int i = 0; i < amountOfThings; i++) { chatFormSettings[i] = ChatFormSettings.Default(); } foreach (var s in (ChatModes[])Enum.GetValues(typeof(ChatModes))) { ChatmodeBox.Items.Add(s); } foreach (var s in (FormBorderStyle[])Enum.GetValues(typeof(FormBorderStyle))) { BorderstyleBox.Items.Add(s); } radioButton1.Checked = true; }
public SettingsLoader(TwitchSettings twitchSettings) { _twitchSettings = twitchSettings; }
private void ConfigureClient(TwitchSettings settings) { client.BaseAddress = new Uri(twitchApiUri); client.DefaultRequestHeaders.Add("Client-ID", settings.ClientId); client.DefaultRequestHeaders.Add("Accept", "application/vnd.twitchtv.v5+json"); }
public Proxy(HttpClient client, TwitchSettings settings) { this.client = client; ConfigureClient(settings); }
public TwitchService(TwitchSettings twitchSettings) { Client = new TwitchClient(); _twitchSettings = twitchSettings; }
public TwitchAuthController(TwitchEbooksContext context, TwitchSettings settings, ILogger <TwitchAuthController> logger) { _context = context ?? throw new ArgumentNullException(nameof(context)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public TwitchService(IOptions <TwitchSettings> twitchSettings) { _twitchSettings = twitchSettings.Value; }
public AuthenticationService(TwitchSettings twitchSettings, IHttpClientFactory clientFactory) { _twitchSettings = twitchSettings; _clientFactory = clientFactory; }