public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopeFactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = false; output.Type = Eventbus.EventType.CommandResponseReceived; string message = "No User found/in List"; if (args.elevatedPermissions && (args.Message.ToLower().StartsWith(Trigger) || args.Message.ToLower().StartsWith(Alias))) { output.ExecuteEvent = true; using (var scope = scopeFactory.CreateScope()) { var _context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var delete = _context.RandomChatUser.Where(x => x.Stream == args.ChannelName && x.lastchecked).FirstOrDefault(); if (delete != null) { _context.RandomChatUser.Remove(delete); _context.SaveChanges(); } if (_context.RandomChatUser.Where(x => x.Stream == args.ChannelName).Count() > 0) { var user = _context.RandomChatUser.Where(x => x.Stream == args.ChannelName).OrderBy(s => s.Sort).First(); user.lastchecked = true; _context.SaveChanges(); message = user.ChatUser; } } output.EventData = new CommandResponseArgs(args.Type, message, MessageType.ChannelMessage, args.Sender, args.ChannelName); } return(output); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopeFactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = false; output.Type = Eventbus.EventType.CommandResponseReceived; string message = "No User found/in List"; if (args.elevatedPermissions && (args.Message.ToLower().StartsWith(Trigger) || args.Message.ToLower().StartsWith(Alias))) { output.ExecuteEvent = true; using (var scope = scopeFactory.CreateScope()) { var _context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); if (_context.RandomChatUser.Where(x => x.Stream == args.ChannelName).Count() > 0) { message = "Users in List: "; foreach (var user in _context.RandomChatUser.Where(x => x.Stream == args.ChannelName).OrderBy(s => s.Sort)) { message += user.ChatUser + "\n"; } } } output.EventData = new CommandResponseArgs(args.Type, message, MessageType.ChannelMessage, args.Sender, args.ChannelName); } return(output); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopefactory) { if (args.elevatedPermissions) { var strawpollargs = extractStrawpollData(args.Message); strawpollargs.StreamName = args.ChannelName; switch (args.Type) { case ChatType.Discord: throw new NotImplementedException("Discord has not yet been implemented for Strawpollcommand"); break; case ChatType.Twitch: strawpollargs.Type = StreamProviderTypes.Twitch; break; default: return(null); } return(new ChatCommandOutput() { Type = Eventbus.EventType.StrawPollRequested, ExecuteEvent = true, EventData = strawpollargs }); } return(null); }
public async Task handleCommand_Strawpoll_StrawPollRequestedEventTriggered() { IServiceScopeFactory scopefactory = Substitute.For <IServiceScopeFactory>(); IEventBus eventbus = new EventBusLocal(); StrawPollRequestEventArgs receivedEventsArgs = null; //eventbus.TriggerEvent(EventType.).For CommandService service = new CommandService(scopefactory, eventbus); eventbus.StrawPollRequested += delegate(object sender, StrawPollRequestEventArgs e) { receivedEventsArgs = e; }; ChatCommandInputArgs args = new ChatCommandInputArgs() { Message = "!strawpoll Tolle Frage hier? | antwort 1 | antwort2", Sender = "chromos33", ChannelName = "deathmic", Type = BobDeathmic.Data.Enums.ChatType.Twitch, elevatedPermissions = true }; await service.handleCommand(args, BobDeathmic.Data.Enums.ChatType.Twitch, "deathmic"); Assert.AreNotEqual(null, receivedEventsArgs); Assert.AreEqual("Tolle Frage hier?", receivedEventsArgs.Question); Assert.AreEqual(2, receivedEventsArgs.Answers.Length); Assert.AreEqual("deathmic", receivedEventsArgs.StreamName); Assert.AreEqual(StreamProviderTypes.Twitch, receivedEventsArgs.Type); }
public async Task handleCommand_TitleCommand_StreamTitleChangeEventTriggered() { IServiceScopeFactory scopefactory = Substitute.For <IServiceScopeFactory>(); IEventBus eventbus = new EventBusLocal(); StreamTitleChangeArgs receivedEventsArgs = null; //eventbus.TriggerEvent(EventType.).For CommandService service = new CommandService(scopefactory, eventbus); eventbus.StreamTitleChangeRequested += delegate(object sender, StreamTitleChangeArgs e) { receivedEventsArgs = e; }; ChatCommandInputArgs args = new ChatCommandInputArgs() { Message = "!title neuer spiele titel", Sender = "chromos33", ChannelName = "deathmic", Type = BobDeathmic.Data.Enums.ChatType.Twitch, elevatedPermissions = true }; await service.handleCommand(args, BobDeathmic.Data.Enums.ChatType.Twitch, "deathmic"); Assert.AreNotEqual(null, receivedEventsArgs); Assert.AreEqual("neuer spiele titel", receivedEventsArgs.Title); Assert.AreEqual("deathmic", receivedEventsArgs.StreamName); Assert.AreEqual(StreamProviderTypes.Twitch, receivedEventsArgs.Type); }
public async Task handleCommand_PickNextRand_CommandResponseReceivedEventTriggered() { DbContextOptions <ApplicationDbContext> options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Test") .Options; IServiceScope scope = Substitute.For <IServiceScope>(); scope.ServiceProvider.GetService(typeof(ApplicationDbContext)).ReturnsForAnyArgs(new ApplicationDbContext(options)); IServiceScopeFactory scopefactory = Substitute.For <IServiceScopeFactory>(); scopefactory.CreateScope().ReturnsForAnyArgs(scope); IEventBus eventbus = new EventBusLocal(); CommandResponseArgs receivedEventsArgs = null; //eventbus.TriggerEvent(EventType.).For CommandService service = new CommandService(scopefactory, eventbus); eventbus.CommandOutputReceived += delegate(object sender, CommandResponseArgs e) { receivedEventsArgs = e; }; ChatCommandInputArgs args = new ChatCommandInputArgs() { Message = "!randnext", Sender = "chromos33", ChannelName = "deathmic", Type = BobDeathmic.Data.Enums.ChatType.Twitch, elevatedPermissions = true }; await service.handleCommand(args, BobDeathmic.Data.Enums.ChatType.Twitch, "deathmic"); Assert.AreNotEqual(null, receivedEventsArgs); Assert.AreEqual("chromos33", receivedEventsArgs.Sender); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopeFactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = false; output.Type = Eventbus.EventType.CommandResponseReceived; string message = "No User found/in List"; if (args.elevatedPermissions && (args.Message.ToLower().StartsWith(Trigger) || args.Message.ToLower().StartsWith(Alias))) { output.ExecuteEvent = true; using (var scope = scopeFactory.CreateScope()) { var _context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var delete = _context.RandomChatUser.Where(x => x.Stream == args.ChannelName && x.lastchecked).FirstOrDefault(); if (delete != null) { _context.RandomChatUser.Remove(delete); _context.SaveChanges(); } if (_context.RandomChatUser.Where(x => x.Stream == args.ChannelName).Count() > 0) { if (_context.RandomChatUser.Where(x => x.Stream == args.ChannelName).Count() == 1) { _context.RandomChatUser.Where(x => x.Stream == args.ChannelName).FirstOrDefault().lastchecked = true; _context.SaveChanges(); message = _context.RandomChatUser.Where(x => x.Stream == args.ChannelName).FirstOrDefault().ChatUser; } else { var users = _context.RandomChatUser.Where(x => x.Stream == args.ChannelName); var count = users.Count(); List <string> Names = new List <string>(); foreach (RandomChatUser usertemplate in users) { for (int i = count; i > 0; i--) { Names.Add(usertemplate.ChatUser); } count--; } var nextuser = Names[rnd.Next(Names.Count() + 1)]; try { _context.RandomChatUser.Where(x => x.ChatUser == nextuser).First().lastchecked = true; _context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } message = nextuser; } } } output.EventData = new CommandResponseArgs(args.Type, message, MessageType.ChannelMessage, args.Sender, args.ChannelName); } return(output); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopefactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = true; output.Type = Eventbus.EventType.CommandResponseReceived; string message = ""; using (var scope = scopefactory.CreateScope()) { var _context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var GiveAwayItem = _context.GiveAwayItems.Include(x => x.Applicants).Where(x => x.current).FirstOrDefault(); if (GiveAwayItem.Applicants == null) { GiveAwayItem.Applicants = new List <User_GiveAwayItem>(); } var user = _context.ChatUserModels.Where(x => x.ChatUserName.ToLower() == args.Sender.ToLower()).FirstOrDefault(); if (GiveAwayItem.Applicants.Where(x => x.UserID == user.Id).Count() == 0) { var item = _context.GiveAwayItems.Where(x => x.current).FirstOrDefault(); if (user != null && item != null) { User_GiveAwayItem relation = new User_GiveAwayItem(user, item); relation.User = user; if (user.AppliedTo == null) { user.AppliedTo = new List <User_GiveAwayItem>(); } if (item.Applicants == null) { item.Applicants = new List <User_GiveAwayItem>(); } user.AppliedTo.Add(relation); item.Applicants.Add(relation); message = "Teilnahme erfolgreich"; } else { message = "Gibt nichs zum teilnehmen"; } } else { message = "Nimmst schon teil."; } _context.SaveChanges(); } output.EventData = new CommandResponseArgs( ChatType.Discord, message, MessageType.PrivateMessage, args.Sender, args.ChannelName ); return(output); }
public async Task handleCommand(ChatCommandInputArgs args, ChatType chatType, string sender) { foreach (ICommand command in Commands.Where(x => x.ChatSupported(chatType) && x.isCommand(args.Message))) { ChatCommandOutput output = await command.execute(args, scopefactory); if (output.ExecuteEvent) { eventBus.TriggerEvent(output.Type, output.EventData); } } }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopefactory) { return(null); /* * if (message["message"].ToLower().StartsWith(Trigger) || message["message"].ToLower().StartsWith(alias)) * { * return CommandEventType.TwitchTitle; * } * return CommandEventType.None; */ }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopefactory) { if (!args.elevatedPermissions) { return(null); } return(new ChatCommandOutput() { ExecuteEvent = true, Type = Eventbus.EventType.StreamTitleChangeRequested, EventData = TwitchStreamTitleHelper.PrepareStreamTitleChange(args.ChannelName, args.Message) }); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopefactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = true; output.Type = Eventbus.EventType.CommandResponseReceived; output.EventData = new CommandResponseArgs( args.Type, getHelp(args.Type), MessageType.PrivateMessage, args.Sender, args.ChannelName ); return(output); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopeFactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = false; output.Type = Eventbus.EventType.CommandResponseReceived; string message = "No skippable user found"; if (args.elevatedPermissions && (args.Message.ToLower().StartsWith(Trigger) || args.Message.ToLower().StartsWith(Alias))) { output.ExecuteEvent = true; using (var scope = scopeFactory.CreateScope()) { var _context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); if (_context.RandomChatUser.Where(x => x.Stream == args.ChannelName && x.lastchecked).Count() > 0) { var skippeduser = _context.RandomChatUser.Where(x => x.Stream == args.ChannelName && x.lastchecked).FirstOrDefault(); if (skippeduser != null) { _context.RandomChatUser.Remove(skippeduser); RandomChatUser tmp = new RandomChatUser(); tmp.ChatUser = skippeduser.ChatUser; tmp.lastchecked = false; if (_context.RandomChatUser.Where(x => x.Stream == args.ChannelName).Count() == 0) { tmp.Sort = 1; } else { tmp.Sort = _context.RandomChatUser.Where(x => x.Stream == args.ChannelName).Max(t => t.Sort) + 1; } tmp.Stream = skippeduser.Stream; _context.RandomChatUser.Add(tmp); _context.SaveChanges(); message = "User skipped"; } } } output.EventData = new CommandResponseArgs(args.Type, message, MessageType.ChannelMessage, args.Sender, args.ChannelName); } return(output); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopefactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = false; output.Type = Eventbus.EventType.CommandResponseReceived; string message = ""; using (var scope = scopefactory.CreateScope()) { var _context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var user = _context.ChatUserModels.Where(x => x.ChatUserName.ToLower() == args.Sender.ToLower()).FirstOrDefault(); var remove = _context.User_GiveAway.Where(x => x.UserID == user.Id).FirstOrDefault(); if (remove != null) { _context.User_GiveAway.Remove(remove); _context.SaveChanges(); } } return(output); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopefactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = true; output.Type = Eventbus.EventType.CommandResponseReceived; string message = ""; using (var scope = scopefactory.CreateScope()) { var _context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); if (_context.RandomChatUser.Where(x => x.ChatUser.ToLower() == args.Sender.ToLower() && x.Stream.ToLower() == args.ChannelName.ToLower()).Count() == 0) { RandomChatUser tmp = new RandomChatUser(); tmp.ChatUser = args.Sender; tmp.Stream = args.ChannelName; if (_context.RandomChatUser.Where(x => x.Stream.ToLower() == args.ChannelName.ToLower()).Count() == 0) { tmp.Sort = 1; } else { tmp.Sort = _context.RandomChatUser.Where(x => x.Stream.ToLower() == args.ChannelName.ToLower()).Max(t => t.Sort) + 1; } _context.RandomChatUser.Add(tmp); _context.SaveChanges(); message = "You were added."; } else { message = "Already in the List"; } } output.EventData = new CommandResponseArgs(args.Type, message, MessageType.PrivateMessage, args.Sender, args.ChannelName); return(output); }
public async Task <ChatCommandOutput> execute(ChatCommandInputArgs args, IServiceScopeFactory scopeFactory) { ChatCommandOutput output = new ChatCommandOutput(); output.ExecuteEvent = false; output.Type = Eventbus.EventType.CommandResponseReceived; output.EventData = new CommandResponseArgs() { Channel = args.ChannelName, Chat = args.Type, MessageType = MessageType.ChannelMessage, Sender = args.Sender }; if (!args.Message.ToLower().StartsWith(Trigger) || args.Type != ChatType.Twitch) { return(output); } using (var scope = scopeFactory.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var saMessageSplit = args.Message.Split(" "); // !quote without any arguments prints a random quote of the current streamer. if (saMessageSplit.Length == 1) { output.ExecuteEvent = true; output.EventData.Message = await GetRandomQuoteFromStreamer(args.ChannelName, context); return(output); } // Non mods can only print quotes, not add or delete. if (!args.elevatedPermissions) { return(output); } int iQuoteId; switch (saMessageSplit[1].ToLower()) { case "add": if (saMessageSplit.Length == 2) { output.EventData.Message = "Usage: !quote add <add funny quote here>"; } else { iQuoteId = await AddQuoteToStreamer(args.ChannelName, string.Join(" ", saMessageSplit.Skip(2)), context); output.EventData.Message = "Quote '" + string.Join(" ", saMessageSplit.Skip(2)) + "' added"; } break; case "delete": if (saMessageSplit.Length == 2) { output.EventData.Message = "Usage: !quote delete <quote ID here>"; } if (!int.TryParse(saMessageSplit[2], out iQuoteId)) { output.EventData.Message = $"'{saMessageSplit[2]}' is not a quote ID."; } output.EventData.Message = await DeleteQuoteFromStreamer(args.ChannelName, iQuoteId, context) ? "Quote deleted." : $"Quote ID {iQuoteId} not found."; break; default: if (!int.TryParse(saMessageSplit[1], out iQuoteId)) { output.EventData.Message = $"'{saMessageSplit[1]}' is not a quote ID."; } output.EventData.Message = await GetQuoteFromStreamer(args.ChannelName, iQuoteId, context); break; } return(output); } }