Beispiel #1
0
        void IModule.Install(ModuleManager manager)
        {
            _manager = manager;
            _client = manager.Client;
            _http = _client.Services.Get<HttpService>();
            _settings = _client.Services.Get<SettingsService>()
                .AddModule<StatusModule, Settings>(manager);

            manager.CreateCommands("status", group =>
            {
                group.MinPermissions((int)PermissionLevel.BotOwner);

                group.CreateCommand("enable")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);

                        Channel channel;
                        if (e.Args[0] != "")
                            channel = await _client.FindChannel(e, e.Args[0], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        settings.Channel = channel.Id;
                        await _settings.Save(e.Server, settings);

                        await _client.Reply(e, $"Enabled status reports in {channel.Name}");
                    });
                group.CreateCommand("disable")
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);

                        settings.Channel = null;
                        await _settings.Save(e.Server, settings);

                        await _client.Reply(e, "Disabled status reports on this server.");
                    });
            });

            _client.LoggedIn += (s, e) =>
            {
                if (!_isRunning)
                {
                    Task.Run(Run);
                    _isRunning = true;
                }
            };
        }
Beispiel #2
0
        void IModule.Install(ModuleManager manager)
        {
            _manager = manager;
            _client = manager.Client;
            _http = _client.Services.Get<HttpService>();
            _settings = _client.Services.Get<SettingsService>()
                .AddModule<TwitchModule, Settings>(manager);

            manager.CreateCommands("streams", group =>
            {
                group.MinPermissions((int)PermissionLevel.BotOwner);

                group.CreateCommand("list")
                    .Do(async e =>
                    {
                        StringBuilder builder = new StringBuilder();
                        var settings = _settings.Load(e.Server);
                        foreach (var channel in settings.Channels)
                            builder.AppendLine($"{_client.GetChannel(channel.Key)}:\n   {string.Join(", ", channel.Value.Streams.Select(x => x.Key))}");
                        await _client.Reply(e, "Linked Streams", builder.ToString());
                    });

                group.CreateCommand("add")
                    .Parameter("twitchuser")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);

                        Channel channel;
                        if (e.Args[1] != "")
                            channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        var channelSettings = settings.GetOrAddChannel(channel.Id);
                        if (channelSettings.AddStream(e.Args[0]))
                        {
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Linked stream {e.Args[0]} to {channel.Name}.");
                        }
                        else
                            await _client.Reply(e, $"Stream {e.Args[0]} is already linked to {channel.Name}.");
                    });

                group.CreateCommand("remove")
                    .Parameter("twitchuser")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        Channel channel;
                        if (e.Args[1] != "")
                            channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        var channelSettings = settings.GetOrAddChannel(channel.Id);
                        if (channelSettings.RemoveStream(e.Args[0]))
                        {
                            await _settings.Save(e.Server.Id, settings);
                            await _client.Reply(e, $"Unlinked stream {e.Args[0]} from {channel.Name}.");
                        }
                        else
                            await _client.Reply(e, $"Stream {e.Args[0]} is not currently linked to {channel.Name}.");
                    });

                group.CreateGroup("set", set =>
                {
                    set.CreateCommand("sticky")
                        .Parameter("value")
                        .Parameter("channel", ParameterType.Optional)
                        .Do(async e =>
                        {
                            bool value = false;
                            bool.TryParse(e.Args[0], out value);

                            Channel channel;
                            if (e.Args[1] != "")
                                channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                            else
                                channel = e.Channel;
                            if (channel == null) return;

                            var settings = _settings.Load(e.Server);
                            var channelSettings = settings.GetOrAddChannel(channel.Id);
                            if (channelSettings.UseSticky && !value && channelSettings.StickyMessageId != null)
                            {
                                var msg = channel.GetMessage(channelSettings.StickyMessageId.Value);
                                try { await msg.Delete(); }
                                catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
                            }
                            channelSettings.UseSticky = value;
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Stream sticky for {channel.Name} set to {value}.");
                        });
                });
            });

            _client.Connected += (s, e) =>
            {
                if (!_isRunning)
                {
                    Task.Run(Run);
                    _isRunning = true;
                }
            };
        }
Beispiel #3
0
		void IModule.Install(ModuleManager manager)
		{
			_manager = manager;
			_client = manager.Client;
			_http = _client.Services.Get<HttpService>();
			_settings = _client.Services.Get<SettingsService>()
				.AddModule<GithubModule, Settings>(manager);

			manager.CreateCommands("repos", group =>
			{
				group.MinPermissions((int)PermissionLevel.BotOwner);

				group.CreateCommand("list")
					.Do(async e =>
					{
						StringBuilder builder = new StringBuilder();
						var settings = _settings.Load(e.Server);
						foreach (var repo in settings.Repos.OrderBy(x => x.Key))
							builder.AppendLine($"{repo.Key} [{string.Join(",", repo.Value.Branches)}] => {_client.GetChannel(repo.Value.ChannelId)?.Name ?? "Unknown"}");
						await _client.Reply(e, "Linked Repos", builder.ToString());
					});

				group.CreateCommand("add")
					.Parameter("githubrepo")
					.Parameter("channel", ParameterType.Optional)
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						Channel channel;
						if (e.Args[1] != "")
							channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
						else
							channel = e.Channel;
						if (channel == null) return;

						string url = FilterUrl(e.Args[0]);
						if (settings.AddRepo(url, channel.Id))
						{
							await _settings.Save(e.Server.Id, settings);
							await _client.Reply(e, $"Linked repo {url} to {channel.Name}.");
						}
						else
							await _client.Reply(e, $"Error: Repo {url} is already being watched.");
					});

				group.CreateCommand("remove")
					.Parameter("githubrepo")
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						string url = FilterUrl(e.Args[0]);
						if (settings.RemoveRepo(url))
						{
							await _settings.Save(e.Server.Id, settings);
							await _client.Reply(e, $"Unlinked repo {url}.");
						}
						else
							await _client.Reply(e, $"Error: Repo {url} is not currently being watched.");
					});

				group.CreateCommand("addbranch")
					.Parameter("githubrepo")
					.Parameter("branch")
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						string url = FilterUrl(e.Args[0]);
						var repo = settings.Repos[url];
						if (repo != null)
						{
							if (repo.AddBranch(e.Args[1]))
							{
								await _settings.Save(e.Server.Id, settings);
								await _client.Reply(e, $"Added branch {url}/{e.Args[1]}.");
							}
							else
								await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is already being watched.");
						}
						else
							await _client.Reply(e, $"Error: Repo {url} is not currently being watched.");
					});

				group.CreateCommand("removebranch")
					.Parameter("githubrepo")
					.Parameter("branch")
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						string url = FilterUrl(e.Args[0]);
						var repo = settings.Repos[url];
						if (repo != null)
						{
							if (repo.RemoveBranch(e.Args[1]))
							{
								await _settings.Save(e.Server.Id, settings);
								await _client.Reply(e, $"Removed branch {url}/{e.Args[1]}.");
							}
							else
								await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is not being watched.");
						}
						else
							await _client.Reply(e, $"Error: Repo {url} is not currently being watched.");
					});
			});

			_client.Connected += (s, e) =>
			{
				if (!_isRunning)
				{
					Task.Run(Run);
					_isRunning = true;
				}
			};
		}
Beispiel #4
0
        void IModule.Install(ModuleManager manager)
        {
            _manager = manager;
            _client = manager.Client;
            _http = _client.Services.Get<HttpService>();
            _settings = _client.Services.Get<SettingsService>()
                .AddModule<FeedModule, Settings>(manager);

            manager.CreateCommands("feeds", group =>
            {
                group.MinPermissions((int)PermissionLevel.BotOwner);

                group.CreateCommand("list")
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        var response = settings.Feeds
                            .OrderBy(x => x.Key)
                            .Select(x => $"{x.Key} => {_client.GetChannel(x.Value.ChannelId)?.Name ?? "Unknown"}");
                        await _client.Reply(e, "Linked Feeds", response);
                    });

                group.CreateCommand("add")
                    .Parameter("url")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        Channel channel;
                        if (e.Args[1] != "")
                            channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        if (settings.AddFeed(e.Args[0], channel.Id))
                        {
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Linked feed {e.Args[0]} to {channel.Name}");
                        }
                        else
                            await _client.Reply(e, $"Feed {e.Args[0]} is already linked to a channel.");
                    });

                group.CreateCommand("remove")
                    .Parameter("url")
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        if (settings.RemoveFeed(e.Args[0]))
                        {
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Unlinked feed {e.Args[0]}.");
                        }
                        else
                            await _client.Reply(e, $"Feed {e.Args[0]} is not currently linked to a channel.");
                    });
            });

            _client.Connected += (s, e) =>
            {
                if (!_isRunning)
                {
                    Task.Run(Run);
                    _isRunning = true;
                }
            };
        }