Beispiel #1
0
        //public override User GetOrCreateUser(string id, string name)
        //{
        //    return base.GetOrCreateUser(id.ToLower(), name);
        //}

        //public override User GetUserOrDefaultByName(string id)
        //{
        //    return base.GetUserOrDefaultByName(id.ToLower());
        //}

        // PRIVATE
        void userUpdateTick(object sender, EventArgs e)
        {
            new Task(() =>
            {
                try
                {
                    using (WebClient client = new WebClient())
                    {
                        string response = client.DownloadString($"htt{""}p://tmi.twitch.tv/group/user/{ChannelName.TrimStart('#')}/chatters");
                        dynamic root    = JsonConvert.DeserializeObject <dynamic>(response);

                        Action <string> processUser = (u) =>
                        {
                            User user = GetUserOrDefaultByName(u.ToLower());
                            if (user != null)
                            {
                                user.Points += 3;
                            }
                        };

                        bool isMod = false;

                        dynamic chatters = root.chatters;
                        if (chatters != null)
                        {
                            foreach (string u in chatters?.moderators ?? new string[] { })
                            {
                                if (u.ToLower() == Bot.TwitchBotName)
                                {
                                    isMod = true;
                                }
                                processUser(u);
                            }
                            foreach (string u in chatters?.staff ?? new string[] { })
                            {
                                processUser(u);
                            }
                            foreach (string u in chatters?.admins ?? new string[] { })
                            {
                                processUser(u);
                            }
                            foreach (string u in chatters?.global_mods ?? new string[] { })
                            {
                                processUser(u);
                            }
                            foreach (string u in chatters?.viewers ?? new string[] { })
                            {
                                processUser(u);
                            }
                        }

                        setMessageTimer(isMod);
                    }
                }
                catch (Exception exc)
                {
                    File.WriteAllText("userupdateerror", exc.Message + "\r\n\r\n" + exc.StackTrace);
                }
            }).Start();

            foreach (var u in UsersByID.Values.Where(x => x.Flags.HasFlag(UserFlags.Mod)))
            {
                ModReffleValueAvailable.AddOrUpdate(u.ID, 10000, (key, i) => Math.Min(i + 40, 10000));
            }
        }