public static float Average(this Color color, Channels channels)
        {
            float average = 0;
            int axisCount = 0;

            if (channels.Contains(Channels.R))
            {
                average += color.r;
                axisCount += 1;
            }

            if (channels.Contains(Channels.G))
            {
                average += color.g;
                axisCount += 1;
            }

            if (channels.Contains(Channels.B))
            {
                average += color.b;
                axisCount += 1;
            }

            if (channels.Contains(Channels.A))
            {
                average += color.a;
                axisCount += 1;
            }

            return average / axisCount;
        }
        public static Color Div(this Color color, Color otherVector, Channels channels)
        {
            color.r = channels.Contains(Channels.R) ? color.r / otherVector.r : color.r;
            color.g = channels.Contains(Channels.G) ? color.g / otherVector.g : color.g;
            color.b = channels.Contains(Channels.B) ? color.b / otherVector.b : color.b;
            color.a = channels.Contains(Channels.A) ? color.a / otherVector.a : color.a;

            return color;
        }
        public static Color Lerp(this Color color, Color target, float time, Channels channels)
        {
            color.r = channels.Contains(Channels.R) && Mathf.Abs(target.r - color.r) > epsilon ? Mathf.Lerp(color.r, target.r, time) : color.r;
            color.g = channels.Contains(Channels.G) && Mathf.Abs(target.g - color.g) > epsilon ? Mathf.Lerp(color.g, target.g, time) : color.g;
            color.b = channels.Contains(Channels.B) && Mathf.Abs(target.b - color.b) > epsilon ? Mathf.Lerp(color.b, target.b, time) : color.b;
            color.a = channels.Contains(Channels.A) && Mathf.Abs(target.a - color.a) > epsilon ? Mathf.Lerp(color.a, target.a, time) : color.a;

            return color;
        }
Esempio n. 4
0
        private void GuildsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (TestGuild guild in e.NewItems)
                {
                    foreach (var channel in guild.Channels)
                    {
                        if (!Channels.Contains(channel))
                        {
                            Channels.Add(channel);
                        }
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
            case NotifyCollectionChangedAction.Remove:
                foreach (TestGuild guild in e.NewItems)
                {
                    foreach (var channel in guild.Channels)
                    {
                        Channels.Remove(channel);
                    }
                }
                break;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Joins the specified channel.
        /// </summary>
        public void JoinChannel(string channel, string key = null)
        {
            if (Channels.Contains(channel))
            {
                throw new InvalidOperationException("Client is already present in channel.");
            }

            string joinCmd = string.Format("JOIN {0}", channel);

            if (!string.IsNullOrEmpty(key))
            {
                joinCmd += string.Format(" {0}", key);
            }

            SendRawMessage(joinCmd, channel);

            // account-notify capability
            var flags = WhoxField.Nick | WhoxField.Hostname | WhoxField.AccountName | WhoxField.Username;

            if (Capabilities.IsEnabled("account-notify"))
            {
                Who(channel, WhoxFlag.None, flags, (whoList) =>
                {
                    if (whoList.Count > 0)
                    {
                        foreach (var whoQuery in whoList)
                        {
                            var user     = Users.GetOrAdd(whoQuery.User.Hostmask);
                            user.Account = whoQuery.User.Account;
                        }
                    }
                });
            }
        }
 public void PartChannel(string channel, string reason)
 {
     if (!Channels.Contains(channel))
         throw new InvalidOperationException("Client is not present in channel.");
     SendRawMessage("PART {0} :{1}", channel, reason);
     Channels.Remove(Channels[channel]);
 }
Esempio n. 7
0
 private void Events_ReceivedChatCommand(object sender, ReceivedPluginCommandEventArgs e)
 {
     if (Channels.Contains(e.Channel, StringComparer.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(e.Channel)) //Null or whitespace=  private command
     {
         ExecuteCommand(e.Character, e.Command, e.Arguments, e.Channel);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Sets the topic for the specified channel.
 /// </summary>
 public void SetTopic(string channel, string topic)
 {
     if (!Channels.Contains(channel))
     {
         throw new InvalidOperationException("Client is not present in channel.");
     }
     SendRawMessage("TOPIC {0} :{1}", channel, topic);
 }
Esempio n. 9
0
 /// <summary>
 /// Leaves the specified channel.
 /// </summary>
 public void PartChannel(string channel)
 {
     if (!Channels.Contains(channel))
     {
         throw new InvalidOperationException("Client is not present in channel.");
     }
     SendRawMessage("PART {0}", channel);
 }
Esempio n. 10
0
 /// <summary>
 /// Joins the specified channel.
 /// </summary>
 public void JoinChannel(string channel)
 {
     if (Channels.Contains(channel))
     {
         throw new InvalidOperationException("Client is not already present in channel.");
     }
     SendRawMessage("JOIN {0}", channel);
 }
Esempio n. 11
0
 public void JoinChannel(string channel)
 {
     if (Channels.Contains(channel))
     {
         OnRawMessageRecieved(new Events.RawMessageEventArgs(string.Format("{0} You're already on that channel", channel), false));
         return;
     }
     SendRawMessage("JOIN {0}", channel);
 }
Esempio n. 12
0
 public void SetTopic(string channel, string topic)
 {
     if (!Channels.Contains(channel))
     {
         OnRawMessageRecieved(new Events.RawMessageEventArgs(string.Format("{0} You're not on that channel", channel), false));
         return;
     }
     SendRawMessage("TOPIC {0} :{1}", channel, topic);
 }
Esempio n. 13
0
 public void PartChannel(string channel, string reason)
 {
     if (Channels.Contains(channel))
     {
         OnRawMessageRecieved(new Events.RawMessageEventArgs(string.Format("{0} You're not on that channel", channel), false));
         return;
     }
     SendRawMessage("PART {0} :{1}", channel, reason);
     Channels.Remove(Channels[channel]);
 }
        /// <summary>
        /// Joins multiple channels at once
        /// </summary>
        public void JoinChannels(IList <string> channels, IList <string> keys = null)
        {
            foreach (string channel in channels)
            {
                if (Channels.Contains(channel))
                {
                    throw new InvalidOperationException($"Client is already present in channel {channel}.");
                }
            }

            StringBuilder joinBuilder = new StringBuilder("JOIN ");

            if (keys == null || keys.Count != channels.Count)
            {
                joinBuilder.Append(string.Join(",", channels));
            }
            else
            {
                for (int i = 0; i < channels.Count; i++)
                {
                    joinBuilder.Append(channels[i]);
                    if (!string.IsNullOrEmpty(keys[i]))
                    {
                        joinBuilder.AppendFormat(" {0}", keys[i]);
                    }
                    joinBuilder.Append(',');
                }
            }

            string joinCmd = joinBuilder.ToString();

            SendRawMessage(joinCmd);

            // account-notify capability
            var flags = WhoxField.Nick | WhoxField.Hostname | WhoxField.AccountName | WhoxField.Username;

            if (Capabilities.IsEnabled("account-notify"))
            {
                foreach (string channel in channels)
                {
                    Who(channel, WhoxFlag.None, flags, (whoList) =>
                    {
                        if (whoList.Count > 0)
                        {
                            foreach (var whoQuery in whoList)
                            {
                                var user     = Users.GetOrAdd(whoQuery.User.Hostmask);
                                user.Account = whoQuery.User.Account;
                            }
                        }
                    });
                }
            }
        }
Esempio n. 15
0
 public void Add(RadioChannelViewModel channel)
 {
     if (Channels.Contains(channel))
     {
         throw new ChannelNameNotUniqueException();
     }
     else
     {
         Channels.Add(channel);
         channel.Parent = this;
     }
 }
Esempio n. 16
0
        public void CreateChannel(string name)
        {
            Channel temp = new Channel(name);

            if (Channels.Contains(temp))
            {
                return;
            }

            temp.SendMessageEvent += SendMessageOnEvent;
            Channels.Add(temp);
        }
Esempio n. 17
0
        public string GetChannelOrDefault(string?channel)
        {
            if (string.IsNullOrWhiteSpace(channel))
            {
                return(Default);
            }

            if (!Channels.Contains(channel))
            {
                return(Default);
            }

            return(channel);
        }
Esempio n. 18
0
 public void Remove(RadioChannelViewModel channel)
 {
     if (Channels.Contains(channel))
     {
         Channels.Remove(channel);
         channel.Parent = null;
     }
     else
     {
         if (channel.Parent == this)
         {
             channel.Parent = null;
         }
     }
 }
Esempio n. 19
0
 public void Remove(IChannel channel, IUser user = null)
 {
     if (channel == null)
     {
         throw new ArgumentNullException(nameof(channel));
     }
     if (channel == DefaultChannel)
     {
         return; // exception?
     }
     lock (Sync) {
         Channel chan;
         if (channel is Channel c && Channels.Contains(c))
         {
             chan = c;
         }
        /// <summary>
        /// 登録しているチャンネルのリスト
        /// </summary>
        /// <returns></returns>
        public async Task GetSubscriptionChannelsAsync()
        {
            //var subscriptions = await GetSubscriptionAsync(MyChannelId);
            await Task.Run(async() =>
            {
                var subscriptions = await GetSubscriptionAsync(MyChannelId);

                foreach (var subscription in subscriptions)
                {
                    string channelId   = subscription.Snippet.ResourceId.ChannelId;
                    string channelName = ApiService.GetChannelName(channelId);

                    Channels channel = new Channels(channelId, channelName);

                    if (!Channels.Contains(channel))
                    {
                        Channels.Add(channel);
                    }
                }
            });
        }
Esempio n. 21
0
 public bool CanUseCommandChannel(ulong channelId) => Channels.Count == 0 || Channels.Contains(channelId);
Esempio n. 22
0
        public async Task ProcessCommand(ServiceChannel requestChannel, long userId, string command, params string[] parameters)
        {
            switch (command.ToLower())
            {
            case "start":
            case "help":

                await Send(requestChannel,
                           $@"Voit hallita haluamiasi hälytyksiä lähettällä yksityisviestillä minulle seuraavia komentoja: 
{Prefix}add Salin Nimi  - Lisää salin seurantaan.
{Prefix}remove Salin Nimi  - Poistaa salin seurannasta.
{Prefix}list  - Listaa seuratut salit.
{Prefix}set ProfiiliNimi aika - Asettaa profiilin, vapaaehtoiseen aikakentään voi määrittää kuinka monta {ServiceChannel.GetTimerUnit()} profiili pysyy päällä.
{Prefix}profiles - Listaa profiilit
{Prefix}save ProfiiliNimi - Tallentaa tämän hetkiset salit profiiliin
{Prefix}setdefault ProfiiliNimi - Asettaa halutun profiilin oletukseksi. Oletusprofiili ladataan aluksi ja kun asetetun profiilin aika umpeutuu.
{Prefix}removeprofile ProfiiliNimi - Poistaa profiilin.");

                break;

            case "list":

                if (requestChannel == null || !requestChannel.Gyms.Any())
                {
                    await Send(requestChannel, "Sinulla ei ole yhtään salia seurannassa.");
                }
                else
                {
                    string reply = requestChannel.Gyms.First();
                    foreach (var requestChannelGym in requestChannel.Gyms.Skip(1))
                    {
                        reply = $"{reply}, {requestChannelGym}";
                    }

                    await Send(requestChannel, reply);
                }
                break;

            case "add":
                if (parameters.Length != 1)
                {
                    break;
                }

                if (!Channels.Contains(requestChannel))
                {
                    requestChannel.Gyms.Add(parameters[0]);
                    Channels.Add(requestChannel);
                    await Send(requestChannel, $"{parameters[0]} lisätty.");

                    SaveGyms();
                }
                else
                {
                    if (requestChannel.Operators.Any() && !requestChannel.Operators.Contains(userId))
                    {
                        await Send(requestChannel, "Sinulla ei ole oikeuksia lisätä saleja.");

                        break;
                    }
                    if (!requestChannel.Gyms.Contains(parameters[0]))
                    {
                        requestChannel.Gyms.Add(parameters[0]);
                        await Send(requestChannel, $"{parameters[0]} lisätty.");

                        SaveGyms();
                    }
                }
                break;

            case "remove":

                if (requestChannel.Operators.Any() && !requestChannel.Operators.Contains(userId))
                {
                    await Send(requestChannel, "Sinulla ei ole oikeuksia poistaa saleja.");

                    break;
                }

                if (parameters.Length < 1)
                {
                    await Send(requestChannel, $"Anna poistettavan salin nimi komennon perään Esim. {Prefix}remove Esimerkkisali Numero 1");

                    break;
                }

                if (requestChannel.Gyms.Contains(parameters[0]))
                {
                    requestChannel.Gyms.Remove(parameters[0]);
                    SaveGyms();
                    await Send(requestChannel, $"Sali {parameters[0]} poistettu seurannasta.");
                }
                else
                {
                    await Send(requestChannel, $"Sinulla ei ole salia {parameters[0]} seurannassa. Tarkista kirjoititko salin nimen oikein.");

                    break;
                }
                break;

            case "set":
                if (parameters.Length < 1)
                {
                    await Send(requestChannel, $"Anna profiilin nimi. Esim: {Prefix}Set Työ");
                }
                var splitMessageText = parameters[0].Split(" ", 2);
                int duration         = 0;
                if (splitMessageText.Length > 1 && int.TryParse(splitMessageText[1], out duration))
                {
                }
                if (!requestChannel.SetProfile(splitMessageText[0], duration))
                {
                    await Send(requestChannel, $"Profiilia {splitMessageText[0]} ei löydy.");
                }
                else
                {
                    await Send(requestChannel, $"Profiili {splitMessageText[0]} asetettu aktiiviseksi.");

                    if (duration > 0)
                    {
                        await Send(requestChannel, $"Vakioprofiili asetetaan takaisin {duration} {ServiceChannel.GetTimerUnit()} päästä.");
                    }
                }

                break;

            case "profiles":
                if (!requestChannel.Profiles.Any())
                {
                    await Send(requestChannel, "Sinulla ei ole profiileja.");

                    break;
                }
                string profiilit = "";
                foreach (var profiili in requestChannel.Profiles)
                {
                    profiilit += $"{profiili.Name} ";
                }
                await Send(requestChannel, profiilit);

                break;

            case "save":
                if (parameters.Length < 1)
                {
                    await Send(requestChannel, $"Anna tallennettavan profiilin nimi. Esim: {Prefix}save Koti");

                    break;
                }
                if (parameters[0].Contains(" "))
                {
                    await Send(requestChannel, "Profiilin nimessä ei saa olla välilyöntejä.");

                    break;
                }
                requestChannel.SaveProfile(parameters[0]);
                SaveGyms();
                await Send(requestChannel, $"Profiili {parameters[0]} tallennettu");

                break;

            case "setdefault":
                if (parameters.Length < 1)
                {
                    await Send(requestChannel, $"Anna profiilin nimi. Esim: {Prefix}SetDefault Koti");
                }
                if (requestChannel.SetDefault(parameters[0]))
                {
                    await Send(requestChannel, $"Profiili {parameters[0]} asetettu oletukseksi.");
                }
                else
                {
                    await Send(requestChannel, $"Profiilia {parameters[0]} ei löytynyt. Tarkista kirjoititko nimen oikein.");
                }
                break;

            case "removeprofile":
                if (parameters.Length < 1)
                {
                    await Send(requestChannel, $"Anna profiilin nimi. Esim: {Prefix}removeprofile Koti");
                }
                if (requestChannel.RemoveProfile(parameters[0]))
                {
                    await Send(requestChannel, $"Profiili {parameters[0]} poistettu.");
                }
                else
                {
                    await Send(requestChannel, $"Profiilia {parameters[0]} ei löytynyt. Tarkista kirjoititko nimen oikein.");
                }
                break;

            case "addoperator":
                if (userId != Master)
                {
                    break;
                }

                if (parameters.Length < 1)
                {
                    await Send(requestChannel, $"Anna käyttäjän nimi");
                }

                break;
            }
        }
Esempio n. 23
0
        public static Color SetValues(this Color color, Color values, Channels channels)
        {
            color.r = channels.Contains(Channels.R) ? values.r : color.r;
            color.g = channels.Contains(Channels.G) ? values.g : color.g;
            color.b = channels.Contains(Channels.B) ? values.b : color.b;
            color.a = channels.Contains(Channels.A) ? values.a : color.a;

            return color;
        }
Esempio n. 24
0
        public static Color Round(this Color color, float step, Channels channels)
        {
            color.r = channels.Contains(Channels.R) ? color.r.Round(step) : color.r;
            color.g = channels.Contains(Channels.G) ? color.g.Round(step) : color.g;
            color.b = channels.Contains(Channels.B) ? color.b.Round(step) : color.b;
            color.a = channels.Contains(Channels.A) ? color.a.Round(step) : color.a;

            return color;
        }
Esempio n. 25
0
        public static Color Pow(this Color color, float power, Channels channels)
        {
            color.r = channels.Contains(Channels.R) ? color.r.Pow(power) : color.r;
            color.g = channels.Contains(Channels.G) ? color.g.Pow(power) : color.g;
            color.b = channels.Contains(Channels.B) ? color.b.Pow(power) : color.b;
            color.a = channels.Contains(Channels.A) ? color.a.Pow(power) : color.a;

            return color;
        }
Esempio n. 26
0
        public static Color Oscillate(this Color color, Color frequency, Color amplitude, Color center, float offset, Channels channels)
        {
            color.r = channels.Contains(Channels.R) ? center.r + amplitude.r * Mathf.Sin(frequency.r * Time.time + offset) : color.r;
            color.g = channels.Contains(Channels.G) ? center.g + amplitude.g * Mathf.Sin(frequency.g * Time.time + offset) : color.g;
            color.b = channels.Contains(Channels.B) ? center.b + amplitude.b * Mathf.Sin(frequency.b * Time.time + offset) : color.b;
            color.a = channels.Contains(Channels.A) ? center.a + amplitude.a * Mathf.Sin(frequency.a * Time.time + offset) : color.a;

            return color;
        }
Esempio n. 27
0
        public void OnChatPacket(PacketReader reader)
        {
            int messageNum = reader.ReadInt16();

            reader.ReadString(4);   // Language

            byte[] packet = reader.GetData();

            switch (messageNum)
            {
            case 0x25:
            {
                int    messageType = reader.ReadInt16();
                string username    = reader.ReadUnicodeString();
                string message     = reader.ReadUnicodeString();

                Match matches = Regex.Match(message, "{(.*)}\\s+(.*)");

                if (matches.Success)
                {
                    string channel = matches.Groups[1].Value;
                    string text    = matches.Groups[2].Value;

                    Messages.Add(new ChatMessage {
                            Username = username, Channel = channel, Text = text
                        });
                    ChatMessageEvent?.Invoke(username, channel, text);
                }

                break;
            }

            case 0x3e8:
            {
                string channel = reader.ReadUnicodeString();

                if (!Channels.Contains(channel))
                {
                    Channels.Add(channel);
                    ChannelCreatedEvent?.Invoke(channel);
                }

                break;
            }

            case 0x3e9:
            {
                string channel = reader.ReadUnicodeString();

                if (Channels.Contains(channel))
                {
                    Channels.Remove(channel);
                    ChannelRemovedEvent?.Invoke(channel);
                }

                break;
            }

            case 0x3ee:
            {
                reader.ReadInt16();
                string userName = reader.ReadUnicodeString();

                if (!Users.Contains(userName))
                {
                    Users.Add(userName);
                    UserJoinedEvent?.Invoke(userName, string.Empty);
                }

                break;
            }

            case 0x3ef:
            {
                string userName = reader.ReadUnicodeString();

                if (Users.Contains(userName))
                {
                    Users.Remove(userName);
                    UserLeftEvent?.Invoke(userName, string.Empty);
                }

                break;
            }

            case 0x3f1:
            {
                CurrentChannel = reader.ReadUnicodeString();
                JoinedChatChannelEvent?.Invoke(CurrentChannel);
                break;
            }

            case 0x3f0:
            {
                Users.Clear();
                ClearUsersEvent?.Invoke();
                break;
            }

            case 0x3f4:
            {
                LeftChatChannelEvent?.Invoke(CurrentChannel);
                CurrentChannel = null;
                break;
            }

            // ReSharper disable once RedundantEmptySwitchSection
            default:
                break;
            }
        }
Esempio n. 28
0
 /// <summary>
 /// Check if a command request is blocked by this policy
 /// </summary>
 /// <param name="message">Message to check</param>
 public bool Blocks(PrivateMessage message) => Mode == PolicyMode.Blacklist && Channels.Contains(message.To) || Mode == PolicyMode.Whitelist && !Channels.Contains(message.To);