Exemple #1
0
        /// <inheritdoc />
        public override Task <IReadOnlyCollection <Channel> > MapChannels(IEnumerable <ChatChannel> channels, CancellationToken cancellationToken) => Task.Factory.StartNew(() =>
        {
            if (channels.Any(x => x.IrcChannel == null))
            {
                throw new InvalidOperationException("ChatChannel missing IrcChannel!");
            }
            lock (this)
            {
                var hs = new HashSet <string>();                // for unique inserts
                foreach (var I in channels)
                {
                    hs.Add(I.IrcChannel);
                }
                var toPart = new List <string>();
                foreach (var I in client.JoinedChannels)
                {
                    if (!hs.Remove(I))
                    {
                        toPart.Add(I);
                    }
                }

                foreach (var I in toPart)
                {
                    client.RfcPart(I, "Pretty nice abscond!");
                }
                foreach (var I in hs)
                {
                    client.RfcJoin(I);
                }

                return((IReadOnlyCollection <Channel>)channels.Select(x =>
                {
                    ulong?id = null;
                    if (!channelIdMap.Any(y =>
                    {
                        if (y.Value != x.IrcChannel)
                        {
                            return false;
                        }
                        id = y.Key;
                        return true;
                    }))
                    {
                        id = channelIdCounter++;
                        channelIdMap.Add(id.Value, x.IrcChannel);
                    }

                    return new Channel
                    {
                        RealId = id.Value,
                        IsAdminChannel = x.IsAdminChannel == true,
                        ConnectionName = address,
                        FriendlyName = channelIdMap[id.Value],
                        IsPrivateChannel = false,
                        Tag = x.Tag
                    };
                }).ToList());
            }
        }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
Exemple #2
0
        /// <summary>
        /// Verlässt den Channel und löscht ihn aus der Datenbank
        /// </summary>
        /// <param name="channel">Der #Channel</param>
        public void PartChannel(string channel)
        {
            ServerChannel chan = Settings.Channels.FirstOrDefault(x => x.Name == channel);

            if (chan == null)
            {
                return;
            }

            _connection.RfcPart(channel);

            using (var context = new BotContext())
            {
                context.Servers.Attach(Settings);
                Settings.Channels.Remove(chan);
                context.SaveChanges();
            }
        }
Exemple #3
0
        /// <summary>
        /// Joins all channels specified in <see cref="IRCConfig"/>
        /// </summary>
        void JoinChannels()
        {
            var hs = new HashSet <string>();            //for unique inserts

            foreach (var I in IRCConfig.AdminChannels)
            {
                hs.Add(I);
            }
            foreach (var I in IRCConfig.DevChannels)
            {
                hs.Add(I);
            }
            foreach (var I in IRCConfig.GameChannels)
            {
                hs.Add(I);
            }
            foreach (var I in IRCConfig.WatchdogChannels)
            {
                hs.Add(I);
            }
            var ToPart = new List <string>();

            foreach (var I in irc.JoinedChannels)
            {
                if (!hs.Remove(I))
                {
                    ToPart.Add(I);
                }
            }
            foreach (var I in ToPart)
            {
                irc.RfcPart(I);
            }
            foreach (var I in hs)
            {
                irc.RfcJoin(I);
            }
        }