mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-25 01:44:12 +00:00
Change references to config
This commit is contained in:
parent
3ac8a209f3
commit
7c41be45e3
2 changed files with 12 additions and 13 deletions
|
@ -9,15 +9,13 @@ Imports NodaTime
|
|||
''' </summary>
|
||||
Class BackgroundWorker
|
||||
Private ReadOnly _bot As BirthdayBot
|
||||
Private ReadOnly _db As Database
|
||||
Private ReadOnly Property WorkerCancel As New CancellationTokenSource
|
||||
Private _workerTask As Task
|
||||
Const Interval = 45 ' How often the worker wakes up, in seconds. Adjust as needed.
|
||||
Private _clock As IClock
|
||||
Private ReadOnly _clock As IClock
|
||||
|
||||
Sub New(instance As BirthdayBot, dbsettings As Database)
|
||||
Sub New(instance As BirthdayBot)
|
||||
_bot = instance
|
||||
_db = dbsettings
|
||||
_clock = SystemClock.Instance ' can replace with FakeClock here when testing
|
||||
End Sub
|
||||
|
||||
|
@ -37,15 +35,15 @@ Class BackgroundWorker
|
|||
Private Async Function WorkerLoop() As Task
|
||||
While Not WorkerCancel.IsCancellationRequested
|
||||
Try
|
||||
' Delay a bit before we start (or continue) work.
|
||||
Await Task.Delay(Interval * 1000, WorkerCancel.Token)
|
||||
|
||||
' Start background tasks.
|
||||
Dim bgTasks As New List(Of Task) From {
|
||||
ReportAsync(),
|
||||
BirthdayAsync()
|
||||
}
|
||||
Await Task.WhenAll(bgTasks)
|
||||
|
||||
' All done. Wait until we have to work again.
|
||||
Await Task.Delay(Interval * 1000, WorkerCancel.Token)
|
||||
Catch ex As TaskCanceledException
|
||||
Return
|
||||
Catch ex As Exception
|
||||
|
@ -284,7 +282,7 @@ Class BackgroundWorker
|
|||
Dim count = _bot.DiscordClient.Guilds.Count
|
||||
Log("Report", $"Currently in {count} guild(s).")
|
||||
|
||||
Dim dtok = _bot._cfg.DBotsToken
|
||||
Dim dtok = _bot.Config.DBotsToken
|
||||
If dtok IsNot Nothing Then
|
||||
Const dUrl As String = "https://discord.bots.gg/api/v1/bots/{0}/stats"
|
||||
|
||||
|
|
|
@ -14,9 +14,10 @@ Class BirthdayBot
|
|||
Private ReadOnly _cmdsMods As ManagerCommands
|
||||
|
||||
Private WithEvents _client As DiscordSocketClient
|
||||
Friend _cfg As Configuration
|
||||
Private ReadOnly _worker As BackgroundWorker
|
||||
|
||||
Friend ReadOnly Property Config As Configuration
|
||||
|
||||
Friend ReadOnly Property DiscordClient As DiscordSocketClient
|
||||
Get
|
||||
Return _client
|
||||
|
@ -27,11 +28,11 @@ Class BirthdayBot
|
|||
Friend ReadOnly Property KnownGuilds As Dictionary(Of ULong, GuildSettings)
|
||||
|
||||
Public Sub New(conf As Configuration, dc As DiscordSocketClient)
|
||||
_cfg = conf
|
||||
Config = conf
|
||||
_client = dc
|
||||
KnownGuilds = New Dictionary(Of ULong, GuildSettings)
|
||||
|
||||
_worker = New BackgroundWorker(Me, conf.DatabaseSettings)
|
||||
_worker = New BackgroundWorker(Me)
|
||||
|
||||
' Command dispatch set-up
|
||||
_dispatchCommands = New Dictionary(Of String, CommandHandler)(StringComparer.InvariantCultureIgnoreCase)
|
||||
|
@ -50,7 +51,7 @@ Class BirthdayBot
|
|||
End Sub
|
||||
|
||||
Public Async Function Start() As Task
|
||||
Await _client.LoginAsync(TokenType.Bot, _cfg.BotToken)
|
||||
Await _client.LoginAsync(TokenType.Bot, Config.BotToken)
|
||||
Await _client.StartAsync()
|
||||
_worker.Start()
|
||||
|
||||
|
@ -69,7 +70,7 @@ Class BirthdayBot
|
|||
Private Function LoadGuild(g As SocketGuild) As Task Handles _client.JoinedGuild, _client.GuildAvailable
|
||||
SyncLock KnownGuilds
|
||||
If Not KnownGuilds.ContainsKey(g.Id) Then
|
||||
Dim gi = GuildSettings.LoadSettingsAsync(_cfg.DatabaseSettings, g.Id).GetAwaiter().GetResult()
|
||||
Dim gi = GuildSettings.LoadSettingsAsync(Config.DatabaseSettings, g.Id).GetAwaiter().GetResult()
|
||||
KnownGuilds.Add(g.Id, gi)
|
||||
End If
|
||||
End SyncLock
|
||||
|
|
Loading…
Reference in a new issue