public User(TwitchLibMessage msg) : base(msg) { Id = msg.UserId; Nickname = msg.DisplayName; Status = msg.Username; Attributes = msg.Badges.Select(t => t.Key + ":" + t.Value).ToArray(); }
public Message(IBot bot, TwitchLibMessage msg) : base(msg) { Bot = bot; UserId = msg.Username; MimeType = "text/plain"; ContentType = ContentType.Text; TimeStamp = DateTime.Now; User = new User(msg); if (msg is ChatMessage) { var chatmsg = (ChatMessage)msg; MessageType = MessageType.Group; Content = chatmsg.Message; GroupId = chatmsg.Channel; Group = new Group(chatmsg); } if (msg is WhisperMessage) { var whisper = (WhisperMessage)msg; MessageType = MessageType.Private; Content = whisper.Message; GroupId = null; } }
public void Setup() { _twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername("doesntmatter") .Build(); _mockMediator = new Mock <IMediator>(); _factory = new TwitchCommandRequestFactory(_mockMediator.Object); // setup a soundeffect to be a valid sound effect _mockMediator.Setup(x => x.Send <ValidSoundEffects>(It.IsAny <SoundEffectLookup>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ValidSoundEffects { SoundEffects = new List <SoundEffectInfo> { new SoundEffectInfo { SoundEffectName = "!soundeffect" } } }); // setup a content command to be a valid content command _mockMediator.Setup(x => x.Send <ValidStaticCommands>(It.IsAny <StaticCommandsLookup>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ValidStaticCommands { Commands = new List <StaticCommandInfo> { new StaticCommandInfo { Command = "staticcommand", Content = "bar" } } }); }
public static UserInfo FromChatMessage(TwitchLibMessage chatMessage, int showsWatched) { UserInfo userInfo = new UserInfo(); userInfo.color = chatMessage.ColorHex; userInfo.displayName = chatMessage.DisplayName; userInfo.showsWatched = showsWatched; userInfo.userName = chatMessage.Username; userInfo.userId = chatMessage.UserId; return(userInfo); }
public TwitchMessage(TwitchLibMessage twitchLibMessage) : base(twitchLibMessage) { Badges = twitchLibMessage.Badges.Select(b => b.Key).ToList(); Color = twitchLibMessage.Color; ColorHex = twitchLibMessage.ColorHex; IsTurbo = twitchLibMessage.IsTurbo; RawIrcMessage = twitchLibMessage.RawIrcMessage; UserId = twitchLibMessage.UserId.ToInt(); UserType = twitchLibMessage.UserType; }
private string HandleCommand(TwitchLibMessage m, string c, string args, bool whisper) { bool sudo() => m is ChatMessage ch && (ch.IsBroadcaster || Settings.IsSudo(m.Username)); bool disallowed() => Settings.SubOnlyBot && !((m is ChatMessage ch && IsSubscriber(ch)) || sudo()); switch (c) { // User Usable Commands case "trade" when !disallowed(): var _ = TwitchCommandsHelper.AddToWaitingList(args, m.DisplayName, m.Username, out string msg); return(msg); case "ts" when !disallowed(): return($"@{m.Username}: {Info.GetPositionString(ulong.Parse(m.UserId))}"); case "tc" when !disallowed(): return($"@{m.Username}: {TwitchCommandsHelper.ClearTrade(ulong.Parse(m.UserId))}"); case "code" when whisper && !disallowed(): return(TwitchCommandsHelper.GetCode(ulong.Parse(m.UserId))); // Sudo Only Commands case "tca" when !sudo(): case "pr" when !sudo(): case "pc" when !sudo(): case "tt" when !sudo(): case "tcu" when !sudo(): return("This command is locked for sudo users only!"); case "tca": Info.ClearAllQueues(); return("Cleared all queues!"); case "pr": return(Info.Hub.Ledy.Pool.Reload() ? $"Reloaded from folder. Pool count: {Info.Hub.Ledy.Pool.Count}" : "Failed to reload from folder."); case "pc": return($"The pool count is: {Info.Hub.Ledy.Pool.Count}"); case "tt": return(Info.Hub.Queues.Info.ToggleQueue() ? "Users are now able to join the trade queue." : "Changed queue settings: **Users CANNOT join the queue until it is turned back on.**"); case "tcu": return(TwitchCommandsHelper.ClearTrade(args)); default: return(null); } }
private async Task AnyMessageReceived( TwitchLibMessage twitchLibMessage, string messageText, MessageSource source) { string?colorHex = twitchLibMessage.ColorHex; User user = await _userRepo.RecordUser(new UserInfo( id : twitchLibMessage.UserId, twitchDisplayName : twitchLibMessage.DisplayName, simpleName : twitchLibMessage.Username, color : string.IsNullOrEmpty(colorHex) ? null : colorHex.TrimStart('#'), fromMessage : true, updatedAt : _clock.GetCurrentInstant() )); var message = new Message(user, messageText, source); IncomingMessage?.Invoke(this, new MessageEventArgs(message)); }
private WhisperMessageBuilder() { _twitchLibMessage = TwitchLibMessageBuilder.Create().Build(); }
public WhisperMessageBuilder WithTwitchLibMessage(TwitchLibMessage twitchLibMessage) { _twitchLibMessage = twitchLibMessage; return(this); }
private ChatMessageBuilder() { _twitchLibMessage = TwitchLibMessageBuilder.Create().Build(); }
private static ChannelAccount ChannelAccountFromTwitchMessage(TwitchLibMessage message) { return(new ChannelAccount(id: message.UserId, name: message.Username, role: message.UserType.ToString())); }