Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
+ 顏色更新 伺服器/頻道選擇
  • Loading branch information
InterfaceGUI committed Mar 11, 2022
1 parent 3e34555 commit 2517e22
Show file tree
Hide file tree
Showing 10 changed files with 668 additions and 50 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions DiscordGameServersStatus/DiscordGameServersStatus/DGSS.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,9 @@
AAAAAAAAAAAf////AAAAAAAAAAAAAAAAf/8=
</value>
</data>
<metadata name="BackgroundWorker2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>941, 17</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAgIAAAAEAIAAoCAEAFgAAACgAAACAAAAAAAEAAAEAIAAAAAAAAAABAEosAABKLAAAAAAAAAAA
Expand Down
145 changes: 112 additions & 33 deletions DiscordGameServersStatus/DiscordGameServersStatus/DGSS.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@ Imports Discord.WebSocket
Imports System.Net
Imports DiscordGameServersStatus.Server.Ping
Imports SSQLib

Public Class DGSS

Dim Discord As DiscordSocketClient
Dim Start As Boolean
Public DiscordClient As DiscordSocketClient
Public Start As Boolean
Dim Time() As Int32 = {600000, 1200000, 1800000, 3600000} ' 10分鐘,20分鐘,30分鐘,60分鐘
Dim msg As Rest.RestUserMessage
Public Guilds
Dim ver As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'取得版本資訊
Me.Size = New Size(236, 380)
If Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then
ver = Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()
Label4.Text = "Ver:" & ver
End If
'--------------------------------------

'初始化Dsicord-------------------
Discord = New DiscordSocketClient(New DiscordSocketConfig With {
DiscordClient = New DiscordSocketClient(New DiscordSocketConfig With {
.MessageCacheSize = 20
})
'--------------------------------------

ComboBox1.SelectedIndex = My.Settings.Timer
MainTimer.Interval = Time(My.Settings.Timer)
Button4.Enabled = False
AddHandler Discord.Ready, AddressOf Ready
AddHandler DiscordClient.Ready, AddressOf Ready

If ver <> My.Settings.lastver Then

Expand All @@ -40,6 +43,7 @@ Public Class DGSS
End Sub

Private Sub DGSS_Resize(sender As Object, e As EventArgs) Handles Me.Resize

If sender.WindowState = FormWindowState.Minimized Then
Me.Visible = False
NotifyIcon1.Visible = True
Expand All @@ -55,7 +59,12 @@ Public Class DGSS

Function Ready() As Task
UpdateShowDialog()
Guilds = DiscordClient.Guilds
BackgroundWorker2.RunWorkerAsync()

End Function


Private Delegate Sub ShowDialogCallBack()
Private Sub UpdateShowDialog()
If Me.InvokeRequired() Then
Expand Down Expand Up @@ -83,8 +92,8 @@ Public Class DGSS
Start = Not Start
If Start Then
Try
Await Discord.LoginAsync(TokenType.Bot, My.Settings.token)
Await Discord.StartAsync
Await DiscordClient.LoginAsync(TokenType.Bot, My.Settings.token)
Await DiscordClient.StartAsync
StartButton.Enabled = False
Catch ex As Exception
Start = False
Expand All @@ -99,8 +108,8 @@ Public Class DGSS
StartButton.Enabled = True
End Try
Else
Await Discord.LogoutAsync
Await Discord.StopAsync
Await DiscordClient.LogoutAsync
Await DiscordClient.StopAsync
StartButton.Text = "啟動"
Label2.Text = "停止"
Label2.ForeColor = Drawing.Color.Black
Expand All @@ -112,7 +121,7 @@ Public Class DGSS
End If
End Sub

Private Function GetServersinfo() As List(Of EmbedFieldBuilder)
Private Async Function GetServersinfo() As Task(Of List(Of EmbedFieldBuilder))
Dim EmbedField As New List(Of EmbedFieldBuilder)
Try
Dim ip As String
Expand All @@ -136,7 +145,7 @@ Public Class DGSS
End Try

Dim port As String
Dim online() As String = {"離線 :negative_squared_cross_mark:", "線上 :white_check_mark:"}
Dim online() As String = {"離線 :x:", "線上 :white_check_mark:"}
Try
port = My.Settings.Serversip(i).Split(":")(1)
Catch ex As IndexOutOfRangeException
Expand Down Expand Up @@ -185,9 +194,11 @@ Public Class DGSS
ElseIf My.Settings.ServersGame(i) = "1" Then

If port Is Nothing Then port = 25565

Try

Dim ping As MinecraftServerInfo = MinecraftServerInfo.GetServerInformation(ip, port)


If ping.IsOnline Then

If port Is Nothing Then
Expand All @@ -201,9 +212,9 @@ Public Class DGSS
Else
If ping.isError Then
If port Is Nothing Then
msg = IIf(NShowIP, "", "**伺服器IP:**" & ip) & vbCrLf & "**狀態:** " & ":negative_squared_cross_mark:" & "離線或未知錯誤" & vbCrLf & IIf(My.Settings.ShowErrorMsg, "原因:`" & ping.ErrorMessage & "`", "")
msg = IIf(NShowIP, "", "**伺服器IP:**" & ip) & vbCrLf & "**狀態:** " & ":x:" & "離線或未知錯誤" & vbCrLf & IIf(My.Settings.ShowErrorMsg, "原因:`" & ping.ErrorMessage & "`", "")
Else
msg = IIf(NShowIP, "", "**伺服器IP:**" & My.Settings.Serversip(i)) & vbCrLf & "**狀態:** " & ":negative_squared_cross_mark:" & "離線或未知錯誤" & vbCrLf & IIf(My.Settings.ShowErrorMsg, "原因:`" & ping.ErrorMessage & "`", "")
msg = IIf(NShowIP, "", "**伺服器IP:**" & My.Settings.Serversip(i)) & vbCrLf & "**狀態:** " & ":x:" & "離線或未知錯誤" & vbCrLf & IIf(My.Settings.ShowErrorMsg, "原因:`" & ping.ErrorMessage & "`", "")
End If
Else
End If
Expand Down Expand Up @@ -310,8 +321,8 @@ Public Class DGSS

Private Async Sub DGSS_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
Await Discord.LogoutAsync
Await Discord.StopAsync
Await DiscordClient.LogoutAsync
Await DiscordClient.StopAsync
Catch ex As Exception
End Try
End Sub
Expand All @@ -324,41 +335,41 @@ Public Class DGSS
.Title = ":scroll:各伺服器狀態",
.Description = "",
.Color = My.Settings.Color,
.Fields = GetServersinfo(),
.Fields = Await GetServersinfo(),
.Timestamp = Date.UtcNow,
.Footer = New EmbedFooterBuilder With {
.IconUrl = "https://i.imgur.com/UNPFf1f.jpg",
.Text = "BOT made by LarsHagrid."
}
}

Catch ex As Exception
Catch

End Try

Try
message = Await Discord.GetGuild(My.Settings.dcServerID).GetTextChannel(My.Settings.channel).GetMessageAsync(My.Settings.MessageID)
message = Await DiscordClient.GetGuild(My.Settings.dcServerID).GetTextChannel(My.Settings.channel).GetMessageAsync(My.Settings.MessageID)
Catch ex As Exception

End Try

Try
If message Is Nothing Then
message = Await Discord.GetGuild(My.Settings.dcServerID).GetTextChannel(My.Settings.channel).SendMessageAsync("", False, embed.Build)
'message = Await Discord.GetGuild(Discord.Guilds(0).Id).GetTextChannel(My.Settings.channel).SendMessageAsync("", False, embed.Build)
My.Settings.MessageID = message.Id
My.Settings.Save()
Else
Await message.ModifyAsync(Function(x)
x.Content = ""
x.Embed = embed.Build
End Function)
End If
Catch ex As Exception
' Try
If message Is Nothing Then
message = Await DiscordClient.GetGuild(My.Settings.dcServerID).GetTextChannel(My.Settings.channel).SendMessageAsync("", False, embed.Build)
'message = Await Discord.GetGuild(Discord.Guilds(0).Id).GetTextChannel(My.Settings.channel).SendMessageAsync("", False, embed.Build)
My.Settings.MessageID = message.Id
My.Settings.Save()
Else
Await message.ModifyAsync(Function(x)
x.Content = ""
x.Embed = embed.Build
End Function)
End If
' Catch ex As Exception

MsgBox(ex.Message)
'MsgBox(ex.Message)

End Try
'End Try

End Sub

Expand All @@ -380,5 +391,73 @@ Public Class DGSS

End Sub

Private Sub BackgroundWorker2_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
Dim numberToCompute As Int16 = Guilds.count
Dim k As Int16 = 1
SelectServer_Channel.ImageList_Guilds.Images.Clear()

For Each x In Guilds

Dim item As New ListViewItem
item.Text = x.Name

If x.IconUrl Is Nothing Then

Else
updateImageList_Guilds(x.Id, x.IconUrl)
item.ImageKey = x.Id
End If

item.SubItems.Add(x.Id.ToString)
UpdateServerListView(item)

UpdataUI(1, CInt((k / numberToCompute) * 100))
k += 1
Next
End Sub

Private Delegate Sub ImageList_GuildsCallBack(ByVal Id As String, ByVal IconUrl As String)
Private Sub updateImageList_Guilds(ByVal Id As String, ByVal IconUrl As String)
If Me.InvokeRequired() Then

Dim cb As New ImageList_GuildsCallBack(AddressOf updateImageList_Guilds)
Me.Invoke(cb, Id, IconUrl)

Else

SelectServer_Channel.ImageList_Guilds.Images.Add(Id, SelectServer_Channel.GetImageFromURL(IconUrl))

End If
End Sub

Private Delegate Sub UpdataUICallBack(ByVal index As Int16, ByVal vaule As Object)
Private Sub UpdataUI(ByVal index As Int16, ByVal vaule As Object)
If Me.InvokeRequired() Then
Dim cb As New UpdataUICallBack(AddressOf UpdataUI)
Me.Invoke(cb, index, vaule)
Else
Select Case index
Case 0

Case 1
SelectServer_Channel.ToolStripProgressBar1.Style = ProgressBarStyle.Blocks
SelectServer_Channel.ToolStripProgressBar1.Value = vaule

End Select
End If
End Sub

Private Delegate Sub ServerListViewCallBack(ByVal item As ListViewItem)
Private Sub UpdateServerListView(ByVal item As ListViewItem)
If Me.InvokeRequired() Then
Dim cb As New ServerListViewCallBack(AddressOf UpdateServerListView)
Me.Invoke(cb, item)
Else

SelectServer_Channel.ListView1.Items.Add(item)

End If
End Sub


End Class
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll</HintPath>
</Reference>
Expand All @@ -132,7 +133,7 @@
<HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SSQLib, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SSQLib.0.9.2\lib\net40\SSQLib.dll</HintPath>
Expand Down Expand Up @@ -189,6 +190,12 @@
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Runtime.Serialization.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.Serialization.Primitives.4.1.1\lib\net46\System.Runtime.Serialization.Primitives.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -266,6 +273,12 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="PingServer.vb" />
<Compile Include="SelectServer_Channel.Designer.vb">
<DependentUpon>SelectServer_Channel.vb</DependentUpon>
</Compile>
<Compile Include="SelectServer_Channel.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="ServerlistForm.Designer.vb">
<DependentUpon>ServerlistForm.vb</DependentUpon>
</Compile>
Expand All @@ -289,6 +302,9 @@
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="SelectServer_Channel.resx">
<DependentUpon>SelectServer_Channel.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="ServerlistForm.resx">
<DependentUpon>ServerlistForm.vb</DependentUpon>
</EmbeddedResource>
Expand Down
Loading

0 comments on commit 2517e22

Please sign in to comment.