Ejemplo n.º 1
0
        public void GetTwitchConfigTest_1()
        {
            TwitchConfig twitch = null;

            try
            {
                twitch = Config.GetTwitchConfig(configLines, 0);
            }
            catch
            {
                Assert.Fail();
            }

            bool assertion = true;

            assertion = (assertion && twitch != null);
            // Twitch username correctly parsed
            assertion = (assertion && twitch.User == "SaiyanBot");
            // Twitch channels correctly parsed
            assertion = (assertion && twitch.Channels.Count == 3);
            assertion = (assertion && twitch.Channels[0] == "gunnerwolfgaming");
            assertion = (assertion && twitch.Channels[1] == "skidsdev");
            assertion = (assertion && twitch.Channels[2] == "tearrotime");

            Assert.IsTrue(assertion);
        }
Ejemplo n.º 2
0
        private bool CheckConfig(TwitchConfig config)
        {
            if (string.IsNullOrWhiteSpace(config.ClientId))
            {
                throw new InvalidOperationException($"TwitchConfig {config.ClientId} is missing");
            }

            if (string.IsNullOrWhiteSpace(config.ClientSecret))
            {
                throw new InvalidOperationException($"TwitchConfig {config.ClientSecret} is missing");
            }

            if (config.Logins == null)
            {
                throw new InvalidOperationException($"TwitchConfig {config.Logins} is null");
            }

            if (config.Logins.Count == 0)
            {
                _logger.LogWarning("TwitchConfig Logins count is 0");
                return(false);
            }

            return(true);
        }
 public TwitchCallOutCommandHandler(TwitchClientServices twitchClientServices, TwitchAPI twitchApiClient, ICacheService cacheService, IOptions <TwitchConfig> config)
 {
     _twitchClientServices = twitchClientServices;
     _twitchApiClient      = twitchApiClient;
     _cacheService         = cacheService;
     _config = config.Value;
 }
Ejemplo n.º 4
0
        private static bool GetDropAvailability(ulong callerId, string callerName, TwitchConfig tcfg, out string error)
        {
            error = string.Empty;
            var cfg = Globals.Bot.Config;

            if (tcfg.IsSudo(callerName))
            {
                return(true);
            }

            if (Globals.Bot.CurrentUserId == callerId)
            {
                return(true);
            }

            if (!cfg.DodoModeConfig.LimitedDodoRestoreOnlyMode)
            {
                error = $"You are only permitted to use this command while on the island during your order, and only if you have forgotten something in your order.";
                return(false);
            }
            else if (!cfg.DodoModeConfig.AllowDrop)
            {
                error = $"AllowDrop is currently set to false is the discord configuration.";
                return(false);
            }

            return(true);
        }
 public TwitchChatNotificationHandler(IMapper mapper, IOptions <TwitchConfig> config, HtmlSanitizer sanitizer, TwitchAPI twitchApiClient, IHubContext <TwitchHub> twitchHub)
 {
     _mapper          = mapper;
     _sanitizer       = sanitizer;
     _twitchApiClient = twitchApiClient;
     _twitchHub       = twitchHub;
     _config          = config.Value;
 }
 public DadJokeCommandHandler(TwitchClientServices twitchClient, IMapper mapper, INotifierMediatorService notifierMediatorService, TwitchAPI twitchApiClient, IHubContext <TwitchHub> twitchHub, DadJokeService service, IOptions <TwitchConfig> config)
 {
     _twitchClient            = twitchClient.Client;
     _mapper                  = mapper;
     _notifierMediatorService = notifierMediatorService;
     _twitchApiClient         = twitchApiClient;
     _service                 = service;
     _config                  = config.Value;
 }
Ejemplo n.º 7
0
 public TwitchWebSocketMiddleware(
     RequestDelegate next,
     TwitchWebSocketManager wsMgr,
     IOptions <TwitchConfig> options)
 {
     _next   = next;
     _wsMgr  = wsMgr;
     _config = options.Value;
 }
Ejemplo n.º 8
0
        internal BaseTwitchClient(TwitchConfig config, TwitchRestApiClient client)
        {
            ApiClient           = client;
            LogManager          = new LogManager(config.LogLevel);
            LogManager.Message += async msg => await _logEvent.InvokeAsync(msg).ConfigureAwait(false);

            _stateLock             = new SemaphoreSlim(1, 1);
            RestLogger             = LogManager.CreateLogger("Rest");
            ApiClient.SentRequest += async(method, endpoint, ms) => await RestLogger.VerboseAsync($"{method} /{endpoint}: {ms} ms");
        }
Ejemplo n.º 9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => false;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.Configure <UserSecrets>(Configuration.GetSection(nameof(UserSecrets)));
            var secrets = Configuration.GetSection(nameof(UserSecrets)).Get <UserSecrets>();

            services.Configure <ConnectedClientSettings>(Configuration.GetSection("ChatClients"));

            // Injected into ChatClients by DI for Hangfire scheduled actions
            var slackConfig = new SlackConfig
            {
                ApiKey         = secrets.SlackApiKey,
                DefaultChannel = Configuration["ChatClients:SlackDefaultChannel"],
            };
            var discordConfig = new DiscordConfig
            {
                DiscordToken   = secrets.DiscordToken,
                DefaultChannel = Configuration["ChatClients:DiscordDefaultChannel"],
            };
            var twitchConfig = new TwitchConfig {
                Username = secrets.TwitchUsername,
                Token    = secrets.TwitchToken,
                Channel  = secrets.TwitchChannel,
            };

            services.AddSingleton(slackConfig);
            services.AddSingleton(discordConfig);
            services.AddSingleton(twitchConfig);

            services.AddSingleton <IConnectedClients, ConnectedClients>();
            services.AddSingleton <IBotSettings, BotSettings>();
            services.AddSingleton <IBotClient, BotGraphClient>();

            services.AddHangfire(x => x.UseSqlServerStorage(secrets.DatabaseConnectionString));

            services.AddDbContext <AppDataContext>(options =>
                                                   options.UseSqlServer(secrets.DatabaseConnectionString));

            services.AddScoped <IRepository, EntityFrameworkRepository>();
            services.AddSingleton <IActionScheduler, HangfireActionScheduler>();
            services.AddSingleton <IAnswerSearchEngine, AnswerSearch>();
            services.AddSingleton <IBot, Core.Bot>();

            RegisterGraphQL.Configure(services, _env);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Ejemplo n.º 10
0
        public void GetTwitchConfigTest_3()
        {
            try
            {
                TwitchConfig twitch = Config.GetTwitchConfig(configLines, -1);
            }
            catch (IndexOutOfRangeException)
            {
                return;
            }

            Assert.Fail();
        }
 public TwitchOrderRequest(T[] order, ulong user, ulong orderId, string trader, string villagerName, TwitchClient client, string channel, TwitchConfig settings, int pass, VillagerRequest?vil)
 {
     UserGuid      = user;
     OrderID       = orderId;
     Trader        = trader;
     Order         = order;
     VillagerName  = villagerName;
     VillagerOrder = vil;
     Client        = client;
     Channel       = channel;
     Settings      = settings;
     Password      = pass;
 }
Ejemplo n.º 12
0
        public void GetTwitchConfigTest_5()
        {
            try
            {
                TwitchConfig twitch = Config.GetTwitchConfig(null, 0);
            }
            catch (ArgumentException)
            {
                return;
            }

            Assert.Fail();
        }
Ejemplo n.º 13
0
        public void GetTwitchConfigTest_4()
        {
            try
            {
                TwitchConfig twitch = Config.GetTwitchConfig(new string[0], 0);
            }
            catch (ArgumentException)
            {
                return;
            }

            Assert.Fail();
        }
Ejemplo n.º 14
0
        public void GetTwitchConfigTest_2()
        {
            try
            {
                TwitchConfig twitch = Config.GetTwitchConfig(configLines, 7);
            }
            catch (ArgumentException)
            {
                return;
            }

            Assert.Fail();
        }
Ejemplo n.º 15
0
 public TwitchWebhooksController(
     TwitchWebSocketManager wsMgr,
     TwitchActionsWebSocketManager fitzyWsMgr,
     IOptions <TwitchConfig> twitchOptions,
     VbContext context,
     IMemoryCache cache,
     ILogger <TwitchWebhooksController> logger)
 {
     _wsMgr        = wsMgr;
     _fitzyWsMgr   = fitzyWsMgr;
     _twitchConfig = twitchOptions.Value;
     _context      = context;
     _cache        = cache;
     _logger       = logger;
 }
Ejemplo n.º 16
0
        public TwitchInfoUpdater(ConfPlugins confPlugins, string streamerLoginName)
        {
            this.streamerLoginName = streamerLoginName;

            var twitchConfigPath = Path.Combine(confPlugins.Path, TwitchConfigFileName);

            twitchConfig = JsonConvert.DeserializeObject <TwitchConfig>(File.ReadAllText(twitchConfigPath));

            TokenSource = new CancellationTokenSource();
            var descUpdaterThread = new Thread(TwitchInfoCollector)
            {
                IsBackground = true
            };

            descUpdaterThread.Start();
        }
Ejemplo n.º 17
0
        public M2Bot(IOptions <TwitchConfig> twitchOptions,
                     IEnumerable <IChatCommand> chatCommands,
                     ILogger <M2Bot> logger)
        {
            _twitchConfig = twitchOptions.Value;
            _chatCommands = chatCommands;
            _logger       = logger;

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

            var socketClient = new WebSocketClient(twitchClientOptions);

            _client = new TwitchClient(socketClient);
        }
Ejemplo n.º 18
0
        public static string Clean(ulong id, string username, TwitchConfig tcfg)
        {
            if (!tcfg.AllowDropViaTwitchChat)
            {
                LogUtil.LogInfo($"{username} is attempting to clean items, however the twitch configuration does not currently allow drop commands", nameof(TwitchCrossBot));
                return(string.Empty);
            }

            if (!GetDropAvailability(id, username, tcfg, out var error))
            {
                return(error);
            }

            if (!Globals.Bot.Config.AllowClean)
            {
                return("Clean functionality is currently disabled.");
            }

            Globals.Bot.CleanRequested = true;
            return("A clean request will be executed momentarily.");
        }
Ejemplo n.º 19
0
        public static string Drop(string message, ulong id, string username, TwitchConfig tcfg)
        {
            if (!tcfg.AllowDropViaTwitchChat)
            {
                LogUtil.LogInfo($"{username} is attempting to drop items, however the twitch configuration does not currently allow drop commands", nameof(TwitchCrossBot));
                return(string.Empty);
            }
            if (!GetDropAvailability(id, username, tcfg, out var error))
            {
                return(error);
            }

            var cfg   = Globals.Bot.Config;
            var items = ItemParser.GetItemsFromUserInput(message, cfg.DropConfig, cfg.DropConfig.UseLegacyDrop ? ItemDestination.PlayerDropped : ItemDestination.HeldItem);

            MultiItem.StackToMax(items);

            if (!InternalItemTool.CurrentInstance.IsSane(items))
            {
                return($"You are attempting to drop items that will damage your save. Drop request not accepted.");
            }

            var MaxRequestCount = cfg.DropConfig.MaxDropCount;
            var ret             = string.Empty;

            if (items.Count > MaxRequestCount)
            {
                ret  += $"Users are limited to {MaxRequestCount} items per command. Please use this bot responsibly. ";
                items = items.Take(MaxRequestCount).ToArray();
            }

            var requestInfo = new ItemRequest(username, items);

            Globals.Bot.Injections.Enqueue(requestInfo);

            ret += $"Item drop request{(requestInfo.Item.Count > 1 ? "s" : string.Empty)} will be executed momentarily.";
            return(ret);
        }
 public TwitchLedFXCommandHandler(WLEDService wledService, TwitchClientServices twitchClientServices, IOptions <TwitchConfig> config)
 {
     _wledService          = wledService;
     _twitchClientServices = twitchClientServices;
     _config = config.Value;
 }
 public TwitchStatsCommandHandler(TwitchAPI twitchApiClient, IOptions <TwitchConfig> config, TwitchClientServices twitchClientServices)
 {
     _twitchApiClient      = twitchApiClient;
     _twitchClientServices = twitchClientServices;
     _config = config.Value;
 }
 public TwitchChatNotificationHandler2(IOptions <TwitchConfig> config, INotifierMediatorService notifierMediatorService)
 {
     _notifierMediatorService = notifierMediatorService;
     _config = config.Value;
 }
 public TwitchUnknownChatCommandHandler(IOptions <TwitchConfig> config, TwitchClientServices twitchClientServices)
 {
     _twitchClientServices = twitchClientServices;
     _config = config.Value;
 }
 public TwitchYeetCommandHandler(TwitchClientServices twitchClient, IOptions <TwitchConfig> config)
 {
     _config       = config.Value;
     _twitchClient = twitchClient.Client;
 }