public ParsedLine(string from, string line, string room, IChatUser user, BotMessageType messageType)
        {
            this.User = user;
            this.Tokens = new Tokens();

            ParseLine(from, room, line, messageType);
        }
Exemple #2
0
        public void changeMainUser(IChatUser user)
        {
            if (MainUser != user)
            {
                MainUser = user;
                foreach (IChatSource source in chatSources.Values)
                {
                    IList <UserAccount> accounts = MainUser.retrieve(source);

                    //Check if there is an existing user account
                    if (accounts != null && accounts.Count > 0)
                    {
                        source.setup(accounts[0]);
                    }
                    else
                    {
                        //Create a new user account
                        UserAccount newAccount;

                        if (MainUser.Profile != null)
                        {
                            //Create a new user with its name as username
                            newAccount = source.createUser(MainUser.Profile.Name);
                        }
                        else
                        {
                            //Create a new user with random username
                            newAccount = source.createUser("User");
                        }
                        newAccount.Owner = MainUser;
                        source.setup(newAccount);
                    }
                }
            }
        }
        private static bool isAllowed(int neededRank, IChatUser user)
        {
            //Disabled: 0; User: 1; Mods: 2; Broadcaster: 3
            bool returner = false;

            switch (neededRank)
            {
            case 0:
                break;

            case 1:
                returner = true;
                break;

            case 2:
                if (user.IsModerator || user.IsBroadcaster)
                {
                    returner = true;
                }
                break;

            case 3:
                if (user.IsBroadcaster)
                {
                    returner = true;
                }
                break;
            }
            return(returner);
        }
        public static JSONObject CustomToJson(this IChatUser chatUser)
        {
            var obj = new JSONObject();

            obj.Add(nameof(chatUser.Id), new JSONString(chatUser.Id ?? ""));
            obj.Add(nameof(chatUser.UserName), new JSONString(chatUser.UserName ?? ""));
            obj.Add(nameof(chatUser.DisplayName), new JSONString(chatUser.DisplayName ?? ""));
            obj.Add(nameof(chatUser.Color), new JSONString(chatUser.Color ?? ""));
            obj.Add(nameof(chatUser.IsBroadcaster), new JSONBool(chatUser.IsBroadcaster));
            obj.Add(nameof(chatUser.IsModerator), new JSONBool(chatUser.IsModerator));
            var badges = new JSONArray();

            if (chatUser.Badges != null)
            {
                foreach (var badge in chatUser.Badges)
                {
                    badges.Add(badge.ToJson());
                }
                obj.Add(nameof(chatUser.Badges), badges);
            }
            if (chatUser is TwitchUser twitchUser)
            {
                obj.Add(nameof(twitchUser.IsSubscriber), twitchUser.IsSubscriber);
                obj.Add(nameof(twitchUser.IsTurbo), twitchUser.IsTurbo);
                obj.Add(nameof(twitchUser.IsVip), twitchUser.IsVip);
            }

            return(obj);
        }
Exemple #5
0
        public Task <IChatUser> GetChatUser(long id)
        {
            IChatUser icu = null;

            Dict_ChatUser.TryGetValue(id, out icu);
            return(Task.FromResult(icu));
        }
Exemple #6
0
        public IChatUser GetChatUser(string id)
        {
            IChatUser icu = default;

            m_Dict_ChatUser.TryGetValue(id, out icu);
            return(icu);
        }
Exemple #7
0
 protected void OnNextUser(IChatUser item)
 {
     foreach (var observer in UserObservers)
     {
         observer.OnNext(item);
     }
 }
Exemple #8
0
        public ParsedLine(string from, string line, string room, IChatUser user, BotMessageType messageType)
        {
            this.User   = user;
            this.Tokens = new Tokens();

            ParseLine(from, room, line, messageType);
        }
 private static void _addRoster(IChatUser user)
 {
     if (!_roster.ContainsKey(user.Bare))
     {
         _roster.Add(user.Bare, user);
     }
 }
Exemple #10
0
        public void SendMessage(string message, IChatUser sender)
        {
            if (!users.Contains(sender))
            {
                sender.Recieve("You are not registered in the chat!", null);
                return;
            }

            if (CommandFilter(message, sender))
            {
                return;
            }

            depth++;
            Debug.WriteLine(depth);

            foreach (IChatUser user in users)
            {
                if (user == sender)
                {
                    continue;
                }
                user.Recieve(message, sender);
            }

            ExecuteKickDepthCheck();
        }
        public IChatUser GetUser(String userId)
        {
            IChatUser result = null;

            _users.TryGetValue(userId.ToLower(), out result);
            return(result);
        }
Exemple #12
0
 public void RegisterUser(IChatUser user)
 {
     if (!_users.Any(u => u.UserId == user.UserId))
     {
         _users.Add(user);
         BuildIndex();
     }
 }
Exemple #13
0
 public void RegisterUser(IChatUser user)
 {
     if (!_users.Any(u => u.UserId == user.UserId))
     {
         _users.Add(user);
         BuildIndex();
     }
 }
Exemple #14
0
 public void SetMyUser(IChatUser value)
 {
     myUser = value;
     if (HasChatUser)
     {
         RaiseGotChatUserEvent();
     }
 }
Exemple #15
0
 public void Recieve(string message, IChatUser sender)
 {
     if (BadWordCheck(message))
     {
         Send("kick " + sender.Id);
         Send("Kicked " + sender.Name + " for saying bad word: " + message);
     }
 }
 public MockedChatMessage(string content, ChatTypes?chatType = null, IChatUser user = null, IChatChannel channel = null, IChatServer server = null)
 {
     Content  = content;
     ChatType = chatType.HasValue ? chatType.Value : ChatTypes.Discord;
     User     = user ?? new MockedChatUser(ChatType);
     Channel  = channel ?? new MockedChatChannel(ChatType);
     Server   = server ?? new MockedChatServer(ChatType);
 }
Exemple #17
0
 public void SetMyUser(IChatUser value)
 {
     Console.WriteLine($"Setting ChatUser {value.DisplayName} - {value.Username} - there is {(GotChatUser != null ? "" : "not")} a subscriber");
     myUser = value;
     if (HasChatUser)
     {
         GotChatUser?.Invoke();
     }
 }
Exemple #18
0
        public ParseState Setup(IChatUser user, string request, CmdFlags flags, string info)
        {
            this._user    = user;
            this._request = request;
            this._flags   = flags;
            this._info    = info;

            return(this);
        }
Exemple #19
0
 public void UnregisterUser(IChatUser user)
 {
     user = _users.FirstOrDefault(u => u.UserId == user.UserId);
     if (user != null)
     {
         _users.Remove(user);
         BuildIndex();
     }
 }
Exemple #20
0
 public void UnregisterUser(IChatUser user)
 {
     user = _users.FirstOrDefault(u => u.UserId == user.UserId);
     if (user != null)
     {
         _users.Remove(user);
         BuildIndex();
     }
 }
Exemple #21
0
        /// <summary>
        /// Has privileges
        /// </summary>
        /// <param name="p_User">Source user</param>
        /// <returns></returns>
        private bool HasPower(IChatUser p_User)
        {
            if (p_User is BeatSaberPlusChatCore.Models.Twitch.TwitchUser)
            {
                var l_TwitchUser = p_User as BeatSaberPlusChatCore.Models.Twitch.TwitchUser;
                return(l_TwitchUser.IsBroadcaster || (Config.ChatRequest.ModeratorPower && l_TwitchUser.IsModerator));
            }

            return(false);
        }
Exemple #22
0
 public RequestInfo(IChatUser requestor, string request, DateTime requestTime, bool isBeatSaverId, ParseState state, CmdFlags flags = 0, string userstring = "")
 {
     this.requestor     = requestor;
     this.request       = request;
     this.isBeatSaverId = isBeatSaverId;
     this.requestTime   = requestTime;
     this.state         = state;
     this.flags         = flags;
     this.requestInfo   = userstring;
 }
Exemple #23
0
 public DynamicText AddUser(IChatUser user)
 {
     try {
         this.Add("user", user.DisplayName);
     }
     catch {
         // Don't care. Twitch user doesn't HAVE to be defined.
     }
     return(this);
 }
Exemple #24
0
        private void MarkToKick(string guid)
        {
            Guid      id   = Guid.Parse(guid);
            IChatUser user = users.Where(u => u.Id == id).FirstOrDefault();

            if (user != null)
            {
                Debug.WriteLine("User to kick: " + user.Name);
                if (admins.Contains(user))
                {
                    return;
                }
                toKick.Add(user);
            }
        }
Exemple #25
0
 private void OnChatUser(IChatUser user)
 {
     if (user.LeaveTime.HasValue)
     {
         IChatUser leftUser = ChatUsers.FirstOrDefault(u => u.Name == user.Name);
         if (leftUser != null)
         {
             Execute.OnUIThread(() => { ChatUsers.Remove(leftUser); });
         }
     }
     else
     {
         Execute.OnUIThread(() => { ChatUsers.Add(user); });
     }
 }
        /// <summary>
        /// Use this to notify users when join count changes
        /// </summary>
        /// <param name="user"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task DirectMessageUser(IChatUser user, string message)
        {
            if (Config.NoDMUsers.Contains(user.Id))
            {
                return;
            }
            var channel = await user.GetOrCreateDMChannelAsync();

            try
            {
                await channel.SendMessageAsync(message);
            }
            catch (Exception e)
            {
                DoError(e);
            }
        }
        /// <summary>
        /// On channel bits
        /// </summary>
        /// <param name="p_Service">Chat service</param>
        /// <param name="p_Channel">Channel instance</param>
        /// <param name="p_User">User instance</param>
        /// <param name="p_BitsUsed">Bits used</param>
        internal void OnChannelBits(IChatService p_Service, IChatChannel p_Channel, IChatUser p_User, int p_BitsUsed)
        {
            if (!Config.Chat.ShowBitsCheeringEvents)
            {
                return;
            }

            SDK.Unity.MainThreadInvoker.Enqueue(() =>
            {
                var l_NewMessage              = m_MessagePool.Alloc();
                l_NewMessage.Text.text        = $"<color=#FFFFFFBB>[<b>{p_Service.DisplayName}</b>] <b><color={p_User.Color}>@{p_User.DisplayName}</color></b> cheered <b>{p_BitsUsed}</b> bits!</color>";
                l_NewMessage.HighlightEnabled = true;
                l_NewMessage.HighlightColor   = Color.green.ColorWithAlpha(0.24f);

                AddMessage(l_NewMessage);
                m_LastMessage = l_NewMessage;
            });
        }
Exemple #28
0
        public async Task RemoveReactionAsync(string emote, IChatUser user, object options = null)
        {
            RequestOptions roptions = null;

            if (options != null && options is RequestOptions)
            {
                roptions = (RequestOptions)options;
            }

            if (_message.Channel is SocketGuildChannel)
            {
                var guildUser = ((SocketGuildChannel)_message.Channel).Guild.Users.FirstOrDefault(x => x.Id == user.Id);

                if (guildUser != null)
                {
                    await _message.RemoveReactionAsync(new Emoji(emote), guildUser, roptions);
                }
            }
        }
Exemple #29
0
        public ParseState Setup(ParseState state, string parameter = null)
        {
            // These are references
            this._user   = state._user;
            this._botcmd = state._botcmd;

            this._flags     = state._flags;
            this._parameter = state._parameter;
            if (parameter != null)
            {
                this._parameter = parameter;
            }
            this._subparameter = state._subparameter;
            this._command      = state._command;
            this._info         = state._info;
            this._sort         = state._sort;

            return(this);
        }
Exemple #30
0
        private bool CommandFilter(string message, IChatUser sender)
        {
            string[] para = message.Split(' ');
            switch (para[0])
            {
            case "addBot":
                SendMessage("Adding Bot");
                AddBot();
                return(true);

            case "kick":
                if (!admins.Contains(sender))
                {
                    sender.Recieve("You don't have permissions to use command: " + para[0], null);
                    return(true);
                }
                MarkToKick(para[1]);
                return(true);

            default:
                break;
            }
            return(false);
        }
 public static bool HasRights(ISRMCommand botcmd, IChatUser user, CmdFlags flags)
 {
     if (flags.HasFlag(CmdFlags.Local))
     {
         return(true);
     }
     if (botcmd.Flags.HasFlag(CmdFlags.Disabled))
     {
         return(false);
     }
     if (botcmd.Flags.HasFlag(CmdFlags.Everyone))
     {
         return(true); // Not sure if this is the best approach actually, not worth thinking about right now
     }
     if (user.IsModerator & RequestBotConfig.Instance.ModFullRights)
     {
         return(true);
     }
     if (user.IsBroadcaster & botcmd.Flags.HasFlag(CmdFlags.Broadcaster))
     {
         return(true);
     }
     if (user.IsModerator & botcmd.Flags.HasFlag(CmdFlags.Mod))
     {
         return(true);
     }
     if (user is TwitchUser twitchUser && twitchUser.IsSubscriber & botcmd.Flags.HasFlag(CmdFlags.Sub))
     {
         return(true);
     }
     if (user is TwitchUser twitchUser1 && twitchUser1.IsVip & botcmd.Flags.HasFlag(CmdFlags.VIP))
     {
         return(true);
     }
     return(false);
 }
 public Task RemoveReactionAsync(string emote, IChatUser user, object options = null)
 {
     throw new NotImplementedException();
 }
 private static void _addRoster(IChatUser user)
 {
     if (!_roster.ContainsKey(user.Bare))
         _roster.Add(user.Bare, user);
 }
 public IEnumerable<IChatUser> GetContacts(IChatUser user)
 {
     return ServiceLocator.GetInstance<IChatContactListProvider>().GetContacts(user.UserId);
 }
Exemple #35
0
 public static BiliBiliChatUser?AsBilibiliUser(this IChatUser user)
 {
     return(user as BiliBiliChatUser);
 }
 public ChatLogonResult(IChatUser user, IEnumerable<IChatUser> users)
 {
     _users = users.Select(u => u.GetContact()).ToList();
     _user = user.GetContact();
     Signed = true;
 }
Exemple #37
0
 public void AddUser(IChatUser chatUser)
 {
     _chatUsers.Add(chatUser);
     Console.WriteLine(string.Format("{0} joined the chatroom.", chatUser.DisplayName));
 }