Updated variable names; added some documentation

This commit is contained in:
Noikoio 2019-05-03 13:17:29 -07:00
parent 75b625970a
commit 11ceadfb36
2 changed files with 23 additions and 19 deletions

View file

@ -10,10 +10,10 @@ Imports NpgsqlTypes
Friend Class GuildSettings Friend Class GuildSettings
Public ReadOnly Property GuildId As ULong Public ReadOnly Property GuildId As ULong
Private ReadOnly _db As Database Private ReadOnly _db As Database
Private _role As ULong? Private _bdayRole As ULong?
Private _channel As ULong? Private _announceCh As ULong?
Private _tz As String Private _tz As String
Private _modded As Boolean Private _moderated As Boolean
Private _userCache As Dictionary(Of ULong, GuildUserSettings) Private _userCache As Dictionary(Of ULong, GuildUserSettings)
Private _roleWarning As Boolean Private _roleWarning As Boolean
@ -61,7 +61,7 @@ Friend Class GuildSettings
''' </summary> ''' </summary>
Public ReadOnly Property RoleId As ULong? Public ReadOnly Property RoleId As ULong?
Get Get
Return _role Return _bdayRole
End Get End Get
End Property End Property
@ -70,7 +70,7 @@ Friend Class GuildSettings
''' </summary> ''' </summary>
Public ReadOnly Property AnnounceChannelId As ULong? Public ReadOnly Property AnnounceChannelId As ULong?
Get Get
Return _channel Return _announceCh
End Get End Get
End Property End Property
@ -89,7 +89,7 @@ Friend Class GuildSettings
''' </summary> ''' </summary>
Public ReadOnly Property IsModerated As Boolean Public ReadOnly Property IsModerated As Boolean
Get Get
Return _modded Return _moderated
End Get End Get
End Property End Property
@ -99,14 +99,14 @@ Friend Class GuildSettings
GuildId = CULng(reader.GetInt64(0)) GuildId = CULng(reader.GetInt64(0))
' Weird: if using a ternary operator with a ULong?, Nothing resolves to 0 despite Option Strict On. ' Weird: if using a ternary operator with a ULong?, Nothing resolves to 0 despite Option Strict On.
If Not reader.IsDBNull(1) Then If Not reader.IsDBNull(1) Then
_role = CULng(reader.GetInt64(1)) _bdayRole = CULng(reader.GetInt64(1))
RoleWarning = False RoleWarning = False
Else Else
RoleWarning = True RoleWarning = True
End If End If
If Not reader.IsDBNull(2) Then _channel = CULng(reader.GetInt64(2)) If Not reader.IsDBNull(2) Then _announceCh = CULng(reader.GetInt64(2))
_tz = If(reader.IsDBNull(3), Nothing, reader.GetString(3)) _tz = If(reader.IsDBNull(3), Nothing, reader.GetString(3))
_modded = reader.GetBoolean(4) _moderated = reader.GetBoolean(4)
' Get user information loaded up. ' Get user information loaded up.
Dim userresult = GuildUserSettings.GetGuildUsersAsync(dbconfig, GuildId) Dim userresult = GuildUserSettings.GetGuildUsersAsync(dbconfig, GuildId)
@ -121,7 +121,6 @@ Friend Class GuildSettings
''' a new instance is created which is capable of adding the user to the database. ''' a new instance is created which is capable of adding the user to the database.
''' </summary> ''' </summary>
''' <param name="userId"></param> ''' <param name="userId"></param>
''' <returns></returns>
Public Function GetUser(userId As ULong) As GuildUserSettings Public Function GetUser(userId As ULong) As GuildUserSettings
If _userCache.ContainsKey(userId) Then If _userCache.ContainsKey(userId) Then
Return _userCache(userId) Return _userCache(userId)
@ -171,7 +170,7 @@ Friend Class GuildSettings
End Function End Function
''' <summary> ''' <summary>
''' Blocks the specified user from issuing commands. ''' Adds the specified user to the block list, preventing them from issuing commands.
''' </summary> ''' </summary>
Public Async Function BlockUserAsync(userId As ULong) As Task Public Async Function BlockUserAsync(userId As ULong) As Task
Using db = Await _db.OpenConnectionAsync() Using db = Await _db.OpenConnectionAsync()
@ -204,13 +203,14 @@ Friend Class GuildSettings
End Function End Function
Public Async Function UpdateRoleAsync(roleId As ULong) As Task Public Async Function UpdateRoleAsync(roleId As ULong) As Task
_role = roleId _bdayRole = roleId
RoleWarning = False _roleWarning = False
_roleLastWarning = New DateTimeOffset
Await UpdateDatabaseAsync() Await UpdateDatabaseAsync()
End Function End Function
Public Async Function UpdateAnnounceChannelAsync(channelId As ULong?) As Task Public Async Function UpdateAnnounceChannelAsync(channelId As ULong?) As Task
_channel = channelId _announceCh = channelId
Await UpdateDatabaseAsync() Await UpdateDatabaseAsync()
End Function End Function
@ -220,7 +220,7 @@ Friend Class GuildSettings
End Function End Function
Public Async Function UpdateModeratedModeAsync(isModerated As Boolean) As Task Public Async Function UpdateModeratedModeAsync(isModerated As Boolean) As Task
_modded = isModerated _moderated = isModerated
Await UpdateDatabaseAsync() Await UpdateDatabaseAsync()
End Function End Function
@ -302,8 +302,8 @@ Friend Class GuildSettings
End If End If
End With End With
With c.Parameters.Add("@ChannelId", NpgsqlDbType.Bigint) With c.Parameters.Add("@ChannelId", NpgsqlDbType.Bigint)
If _channel.HasValue Then If _announceCh.HasValue Then
.Value = _channel.Value .Value = _announceCh.Value
Else Else
.Value = DBNull.Value .Value = DBNull.Value
End If End If
@ -315,7 +315,7 @@ Friend Class GuildSettings
.Value = DBNull.Value .Value = DBNull.Value
End If End If
End With End With
c.Parameters.Add("@Moderated", NpgsqlDbType.Boolean).Value = _modded c.Parameters.Add("@Moderated", NpgsqlDbType.Boolean).Value = _moderated
c.Prepare() c.Prepare()
Await c.ExecuteNonQueryAsync() Await c.ExecuteNonQueryAsync()
End Using End Using

View file

@ -2,6 +2,10 @@
Imports Npgsql Imports Npgsql
Imports NpgsqlTypes Imports NpgsqlTypes
''' <summary>
''' Representation of a user's birthday settings within a guild.
''' Instances are held and managed by <see cref="GuildSettings"/>.
''' </summary>
Class GuildUserSettings Class GuildUserSettings
Private _month As Integer Private _month As Integer
Private _day As Integer Private _day As Integer
@ -38,7 +42,7 @@ Class GuildUserSettings
''' <summary> ''' <summary>
''' Creates a data-less instance without any useful information. ''' Creates a data-less instance without any useful information.
''' Calling <see cref="UpdateAsync(Integer, Integer, String)"/> will cause an actual database update. ''' Calling <see cref="UpdateAsync(Integer, Integer, String)"/> will create a real database entry.
''' </summary> ''' </summary>
Public Sub New(guildId As ULong, userId As ULong) Public Sub New(guildId As ULong, userId As ULong)
Me.GuildId = guildId Me.GuildId = guildId