Esempio n. 1
0
        void IDataObject.OnDataLoad()
        {
            if (_bttvChannelEmoteSources == null)
            {
                _bttvChannelEmoteSources = new List <BttvChannelEmoteSource>();
            }

            Task.Run(async() =>
            {
                for (int i = 0; i < _bttvChannelEmoteSources.Count; i++)
                {
                    _bttvChannelEmoteSources[i] = await BttvChannelEmoteSource.Create(_client,
                                                                                      _bttvChannelEmoteSources[i].Channel);
                }
            });
        }
Esempio n. 2
0
        void IModule.Install(ModuleManager manager)
        {
            _client = manager.Client;
            _http   = _client.GetService <HttpService>();

            Task.Run(async() =>
            {
                foreach (EmoteSourceBase source in _emoteSources)
                {
                    try
                    {
                        await source.DownloadData(_http);
                    }
                    catch (Exception ex)
                    {
                        Logger.FormattedWrite(
                            GetType().Name,
                            $"Failed loading emotes for {source.GetType().Name}. Exception: {ex}");
                    }
                }
                GC.Collect();
            });

            manager.CreateDynCommands("bttv", PermissionLevel.User, group =>
            {
                group.CreateCommand("")
                .Parameter("channel")
                .Description("Add a BTTV channel to the emote sources.")
                .Do(async e =>
                {
                    string channel = e.GetArg("channel");

                    if (_bttvChannelEmoteSources.FirstOrDefault(s => s.Channel == channel) != null)
                    {
                        await e.Channel.SendMessage("This channel is already in the emote source list.");
                        return;
                    }

                    BttvChannelEmoteSource source = await BttvChannelEmoteSource.Create(_client, channel);
                    if (source == null)
                    {
                        await e.Channel.SafeSendMessage("Failed getting emote data.");
                        return;
                    }

                    _bttvChannelEmoteSources.Add(source);
                    await e.Channel.SafeSendMessage($"Added channel {channel} to the emote source.");
                });
            });

            manager.CreateDynCommands("emote", PermissionLevel.User, group =>
            {
                group.CreateCommand("")
                .Parameter("emote", ParameterType.Unparsed)
                .Do(async e =>
                {
                    string emotePath = await ResolveEmoteDir(e.GetArg("emote"));

                    if (!File.Exists(emotePath))
                    {
                        return;     // todo : lower case == upper case in this case. KAPPA = Kappa
                    }
                    await e.Channel.SafeSendFile(emotePath);
                });
            });
        }