-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBotController.cs
More file actions
56 lines (46 loc) · 1.43 KB
/
Copy pathBotController.cs
File metadata and controls
56 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.AspNetCore.Mvc;
using RumbleBotApi.Models;
using RumbleLib;
using RumbleViewBot;
namespace RumbleBotApi.Controllers;
[ApiController]
[Route("api/bot")]
public class BotController : ControllerBase
{
private readonly BotManager _botManager;
public BotController(BotManager botManager)
{
_botManager = botManager;
}
[HttpPost("task")]
public async Task<IActionResult> CreateTask([FromBody] StartNewTaskSettings settings)
{
var rumbleTask = await _botManager.StartNewTask(settings);
return CreatedAtAction(nameof(GetTaskStatus), new { id = rumbleTask.Id }, rumbleTask);
}
[HttpGet("task/{id}")]
public Task<IActionResult> GetTaskStatus(string id)
{
var watchChannelTask = _botManager.GetTask(id);
if (watchChannelTask == null)
{
return Task.FromResult<IActionResult>(NotFound($"RumbleTask with ID '{id}' not found."));
}
return Task.FromResult<IActionResult>(Ok(watchChannelTask));
}
[HttpDelete("task/{id}")]
public IActionResult StopTask(string id)
{
if (_botManager.StopTask(id))
{
return Ok($"Task with ID '{id}' was stopped successfully.");
}
return NotFound($"Task with ID '{id}' not found.");
}
[HttpGet("tasks")]
public IActionResult ListTasks()
{
var tasks = _botManager.ListTasks();
return Ok(tasks);
}
}