-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
PokeBotRunnerImpl.cs
91 lines (78 loc) · 3.04 KB
/
PokeBotRunnerImpl.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using PKHeX.Core;
using SysBot.Pokemon.Discord;
using SysBot.Pokemon.Twitch;
using SysBot.Pokemon.WinForms;
using SysBot.Pokemon.YouTube;
using SysBot.Pokemon.Web;
using System.Threading;
using System.Threading.Tasks;
namespace SysBot.Pokemon
{
/// <summary>
/// Bot Environment implementation with Integrations added.
/// </summary>
public class PokeBotRunnerImpl<T> : PokeBotRunner<T> where T : PKM, new()
{
public PokeBotRunnerImpl(PokeTradeHub<T> hub, BotFactory<T> fac) : base(hub, fac) { }
public PokeBotRunnerImpl(PokeTradeHubConfig config, BotFactory<T> fac) : base(config, fac) { }
private TwitchBot<T>? Twitch;
private YouTubeBot<T>? YouTube;
private static WebBot<T>? Web;
protected override void AddIntegrations()
{
AddDiscordBot(Hub.Config.Discord.Token);
AddTwitchBot(Hub.Config.Twitch);
AddYouTubeBot(Hub.Config.YouTube);
AddWebBot(Hub.Config.Web);
}
private void AddTwitchBot(TwitchSettings config)
{
if (string.IsNullOrWhiteSpace(config.Token))
return;
if (Twitch != null)
return; // already created
if (string.IsNullOrWhiteSpace(config.Channel))
return;
if (string.IsNullOrWhiteSpace(config.Username))
return;
if (string.IsNullOrWhiteSpace(config.Token))
return;
Twitch = new TwitchBot<T>(Hub.Config.Twitch, Hub);
if (Hub.Config.Twitch.DistributionCountDown)
Hub.BotSync.BarrierReleasingActions.Add(() => Twitch.StartingDistribution(config.MessageStart));
}
private void AddYouTubeBot(YouTubeSettings config)
{
if (string.IsNullOrWhiteSpace(config.ClientID))
return;
if (YouTube != null)
return; // already created
WinFormsUtil.Alert("Please Login with your Browser");
if (string.IsNullOrWhiteSpace(config.ChannelID))
return;
if (string.IsNullOrWhiteSpace(config.ClientID))
return;
if (string.IsNullOrWhiteSpace(config.ClientSecret))
return;
YouTube = new YouTubeBot<T>(Hub.Config.YouTube, Hub);
Hub.BotSync.BarrierReleasingActions.Add(() => YouTube.StartingDistribution(config.MessageStart));
}
private void AddDiscordBot(string apiToken)
{
if (string.IsNullOrWhiteSpace(apiToken))
return;
var bot = new SysCord<T>(this);
Task.Run(() => bot.MainAsync(apiToken, CancellationToken.None));
}
private void AddWebBot(WebSettings config)
{
if (string.IsNullOrWhiteSpace(config.URIEndpoint))
return;
if (Web != null)
return; // already created
if (string.IsNullOrEmpty(config.URIEndpoint))
return;
Web = new WebBot<T>(Hub.Config.Web, Hub);
}
}
}