diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.Designer.vb b/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.Designer.vb index 9421ebb..f687977 100644 --- a/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.Designer.vb +++ b/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.Designer.vb @@ -45,6 +45,7 @@ Partial Class DGSS Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog() Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog() Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components) + Me.BackgroundWorker2 = New System.ComponentModel.BackgroundWorker() Me.GroupBox1.SuspendLayout() Me.MenuStrip1.SuspendLayout() Me.SuspendLayout() @@ -145,7 +146,7 @@ Partial Class DGSS ' 'Button5 ' - Me.Button5.Location = New System.Drawing.Point(323, 44) + Me.Button5.Location = New System.Drawing.Point(269, 59) Me.Button5.Name = "Button5" Me.Button5.Size = New System.Drawing.Size(98, 51) Me.Button5.TabIndex = 2 @@ -223,11 +224,14 @@ Partial Class DGSS Me.NotifyIcon1.Icon = CType(resources.GetObject("NotifyIcon1.Icon"), System.Drawing.Icon) Me.NotifyIcon1.Text = "Discord Game Status" ' + 'BackgroundWorker2 + ' + ' 'DGSS ' Me.AutoScaleDimensions = New System.Drawing.SizeF(11.0!, 24.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(220, 341) + Me.ClientSize = New System.Drawing.Size(476, 341) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Button6) @@ -271,4 +275,5 @@ Partial Class DGSS Friend WithEvents 載入設定檔ToolStripMenuItem As ToolStripMenuItem Friend WithEvents OpenFileDialog1 As OpenFileDialog Friend WithEvents NotifyIcon1 As NotifyIcon + Friend WithEvents BackgroundWorker2 As System.ComponentModel.BackgroundWorker End Class diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.resx b/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.resx index 1608c82..f1c9298 100644 --- a/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.resx +++ b/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.resx @@ -1268,6 +1268,9 @@ AAAAAAAAAAAf////AAAAAAAAAAAAAAAAf/8= + + 941, 17 + AAABAAEAgIAAAAEAIAAoCAEAFgAAACgAAACAAAAAAAEAAAEAIAAAAAAAAAABAEosAABKLAAAAAAAAAAA diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.vb b/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.vb index 30cf71a..22adc60 100644 --- a/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.vb +++ b/DiscordGameServersStatus/DiscordGameServersStatus/DGSS.vb @@ -3,16 +3,19 @@ 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 @@ -20,7 +23,7 @@ Public Class DGSS '-------------------------------------- '初始化Dsicord------------------- - Discord = New DiscordSocketClient(New DiscordSocketConfig With { + DiscordClient = New DiscordSocketClient(New DiscordSocketConfig With { .MessageCacheSize = 20 }) '-------------------------------------- @@ -28,7 +31,7 @@ Public Class DGSS 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -324,7 +335,7 @@ 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", @@ -332,33 +343,33 @@ Public Class DGSS } } - 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 @@ -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 diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/DiscordGameServersStatus.vbproj b/DiscordGameServersStatus/DiscordGameServersStatus/DiscordGameServersStatus.vbproj index 1e921bb..fe00eec 100644 --- a/DiscordGameServersStatus/DiscordGameServersStatus/DiscordGameServersStatus.vbproj +++ b/DiscordGameServersStatus/DiscordGameServersStatus/DiscordGameServersStatus.vbproj @@ -122,6 +122,7 @@ ..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + ..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll @@ -132,7 +133,7 @@ ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll - ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll ..\packages\SSQLib.0.9.2\lib\net40\SSQLib.dll @@ -189,6 +190,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.Runtime.Serialization.Primitives.4.1.1\lib\net46\System.Runtime.Serialization.Primitives.dll + True + True + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll @@ -266,6 +273,12 @@ True + + SelectServer_Channel.vb + + + Form + ServerlistForm.vb @@ -289,6 +302,9 @@ My.Resources Designer + + SelectServer_Channel.vb + ServerlistForm.vb diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.Designer.vb b/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.Designer.vb index 305f0e2..8a4c138 100644 --- a/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.Designer.vb +++ b/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.Designer.vb @@ -1,9 +1,9 @@ - _ + Partial Class Discordsetting Inherits System.Windows.Forms.Form 'Form 覆寫 Dispose 以清除元件清單。 - _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then @@ -20,7 +20,7 @@ Partial Class Discordsetting '注意: 以下為 Windows Form 設計工具所需的程序 '可以使用 Windows Form 設計工具進行修改。 '請勿使用程式碼編輯器進行修改。 - _ + Private Sub InitializeComponent() Me.TextBoxToken = New System.Windows.Forms.TextBox() Me.Label1 = New System.Windows.Forms.Label() @@ -34,13 +34,15 @@ Partial Class Discordsetting Me.CheckBox2 = New System.Windows.Forms.CheckBox() Me.Label4 = New System.Windows.Forms.Label() Me.ColorDialog1 = New System.Windows.Forms.ColorDialog() + Me.Button3 = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'TextBoxToken ' Me.TextBoxToken.Location = New System.Drawing.Point(109, 9) Me.TextBoxToken.Name = "TextBoxToken" - Me.TextBoxToken.Size = New System.Drawing.Size(554, 30) + Me.TextBoxToken.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42) + Me.TextBoxToken.Size = New System.Drawing.Size(460, 30) Me.TextBoxToken.TabIndex = 0 ' 'Label1 @@ -74,18 +76,18 @@ Partial Class Discordsetting ' 'Button1 ' - Me.Button1.Location = New System.Drawing.Point(450, 52) + Me.Button1.Location = New System.Drawing.Point(373, 109) Me.Button1.Name = "Button1" - Me.Button1.Size = New System.Drawing.Size(103, 41) + Me.Button1.Size = New System.Drawing.Size(91, 56) Me.Button1.TabIndex = 2 Me.Button1.Text = "取消" Me.Button1.UseVisualStyleBackColor = True ' 'Button2 ' - Me.Button2.Location = New System.Drawing.Point(559, 52) + Me.Button2.Location = New System.Drawing.Point(470, 109) Me.Button2.Name = "Button2" - Me.Button2.Size = New System.Drawing.Size(103, 41) + Me.Button2.Size = New System.Drawing.Size(99, 56) Me.Button2.TabIndex = 2 Me.Button2.Text = "確認" Me.Button2.UseVisualStyleBackColor = True @@ -125,7 +127,7 @@ Partial Class Discordsetting ' Me.CheckBox2.AutoSize = True Me.CheckBox2.Font = New System.Drawing.Font("微軟正黑體", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) - Me.CheckBox2.Location = New System.Drawing.Point(180, 106) + Me.CheckBox2.Location = New System.Drawing.Point(155, 106) Me.CheckBox2.Name = "CheckBox2" Me.CheckBox2.Size = New System.Drawing.Size(212, 28) Me.CheckBox2.TabIndex = 3 @@ -136,22 +138,33 @@ Partial Class Discordsetting ' Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.Label4.Font = New System.Drawing.Font("微軟正黑體", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) - Me.Label4.Location = New System.Drawing.Point(450, 105) + Me.Label4.Location = New System.Drawing.Point(12, 137) Me.Label4.Name = "Label4" - Me.Label4.Size = New System.Drawing.Size(212, 28) + Me.Label4.Size = New System.Drawing.Size(355, 28) Me.Label4.TabIndex = 5 Me.Label4.Text = "訊息顏色" Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' + 'Button3 + ' + Me.Button3.Enabled = False + Me.Button3.Location = New System.Drawing.Point(444, 43) + Me.Button3.Name = "Button3" + Me.Button3.Size = New System.Drawing.Size(125, 60) + Me.Button3.TabIndex = 2 + Me.Button3.Text = "取得ID" + Me.Button3.UseVisualStyleBackColor = True + ' 'Discordsetting ' Me.AutoScaleDimensions = New System.Drawing.SizeF(10.0!, 19.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(677, 143) + Me.ClientSize = New System.Drawing.Size(581, 177) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.CheckBox2) Me.Controls.Add(Me.CheckBox1) Me.Controls.Add(Me.Button2) + Me.Controls.Add(Me.Button3) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.TextBox1) @@ -180,4 +193,5 @@ Partial Class Discordsetting Friend WithEvents CheckBox2 As CheckBox Friend WithEvents Label4 As Label Friend WithEvents ColorDialog1 As ColorDialog + Friend WithEvents Button3 As Button End Class diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.vb b/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.vb index bf7605c..a12defd 100644 --- a/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.vb +++ b/DiscordGameServersStatus/DiscordGameServersStatus/Discordsetting.vb @@ -1,5 +1,9 @@ -Public Class Discordsetting +Imports Discord +Imports Discord.WebSocket + +Public Class Discordsetting Private Sub Discordsetting_Load(sender As Object, e As EventArgs) Handles MyBase.Load + TextboxChannel.Text = My.Settings.channel TextBoxToken.Text = My.Settings.token TextBox1.Text = My.Settings.dcServerID @@ -39,4 +43,20 @@ Private Sub Label4_MouseLeave(sender As Object, e As EventArgs) Handles Label4.MouseLeave Cursor = Cursors.Default End Sub + + Private Async Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click + + SelectServer_Channel.ShowDialog() + TextboxChannel.Text = My.Settings.channel + TextBox1.Text = My.Settings.dcServerID + + End Sub + + Private Sub TextBoxToken_TextChanged(sender As Object, e As EventArgs) Handles TextBoxToken.TextChanged + If TextBoxToken.Text.Length > 10 Then + Button3.Enabled = True + End If + End Sub + + End Class \ No newline at end of file diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.Designer.vb b/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.Designer.vb new file mode 100644 index 0000000..809d438 --- /dev/null +++ b/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.Designer.vb @@ -0,0 +1,174 @@ + +Partial Class SelectServer_Channel + Inherits System.Windows.Forms.Form + + 'Form 覆寫 Dispose 以清除元件清單。 + + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + '為 Windows Form 設計工具的必要項 + Private components As System.ComponentModel.IContainer + + '注意: 以下為 Windows Form 設計工具所需的程序 + '可以使用 Windows Form 設計工具進行修改。 + '請勿使用程式碼編輯器進行修改。 + + Private Sub InitializeComponent() + Me.components = New System.ComponentModel.Container() + Me.StatusStrip1 = New System.Windows.Forms.StatusStrip() + Me.ToolStripProgressBar1 = New System.Windows.Forms.ToolStripProgressBar() + Me.ImageList_Guilds = New System.Windows.Forms.ImageList(Me.components) + Me.BackgroundWorker1 = New System.ComponentModel.BackgroundWorker() + Me.ListView1 = New System.Windows.Forms.ListView() + Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.ListView2 = New System.Windows.Forms.ListView() + Me.ColumnHeader3 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.ColumnHeader4 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.Button1 = New System.Windows.Forms.Button() + Me.BackgroundWorker_GetChannel = New System.ComponentModel.BackgroundWorker() + Me.BackgroundWorker_GETServerList = New System.ComponentModel.BackgroundWorker() + Me.StatusStrip1.SuspendLayout() + Me.SuspendLayout() + ' + 'StatusStrip1 + ' + Me.StatusStrip1.AutoSize = False + Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripProgressBar1}) + Me.StatusStrip1.Location = New System.Drawing.Point(0, 323) + Me.StatusStrip1.Name = "StatusStrip1" + Me.StatusStrip1.Size = New System.Drawing.Size(652, 26) + Me.StatusStrip1.SizingGrip = False + Me.StatusStrip1.TabIndex = 0 + Me.StatusStrip1.Text = "StatusStrip1" + ' + 'ToolStripProgressBar1 + ' + Me.ToolStripProgressBar1.MarqueeAnimationSpeed = 30 + Me.ToolStripProgressBar1.Name = "ToolStripProgressBar1" + Me.ToolStripProgressBar1.Size = New System.Drawing.Size(649, 20) + Me.ToolStripProgressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee + Me.ToolStripProgressBar1.Value = 1 + ' + 'ImageList_Guilds + ' + Me.ImageList_Guilds.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit + Me.ImageList_Guilds.ImageSize = New System.Drawing.Size(32, 32) + Me.ImageList_Guilds.TransparentColor = System.Drawing.Color.Transparent + ' + 'BackgroundWorker1 + ' + Me.BackgroundWorker1.WorkerReportsProgress = True + ' + 'ListView1 + ' + Me.ListView1.BackColor = System.Drawing.SystemColors.Window + Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2}) + Me.ListView1.Font = New System.Drawing.Font("微軟正黑體", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) + Me.ListView1.ForeColor = System.Drawing.SystemColors.WindowText + Me.ListView1.FullRowSelect = True + Me.ListView1.GridLines = True + Me.ListView1.HideSelection = False + Me.ListView1.LargeImageList = Me.ImageList_Guilds + Me.ListView1.Location = New System.Drawing.Point(12, 22) + Me.ListView1.MultiSelect = False + Me.ListView1.Name = "ListView1" + Me.ListView1.Size = New System.Drawing.Size(250, 286) + Me.ListView1.SmallImageList = Me.ImageList_Guilds + Me.ListView1.TabIndex = 12 + Me.ListView1.TileSize = New System.Drawing.Size(64, 64) + Me.ListView1.UseCompatibleStateImageBehavior = False + Me.ListView1.View = System.Windows.Forms.View.Details + ' + 'ColumnHeader1 + ' + Me.ColumnHeader1.Text = "ServerName" + Me.ColumnHeader1.Width = 240 + ' + 'ColumnHeader2 + ' + Me.ColumnHeader2.Text = "Id" + Me.ColumnHeader2.Width = 1 + ' + 'ListView2 + ' + Me.ListView2.BackColor = System.Drawing.SystemColors.Window + Me.ListView2.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader3, Me.ColumnHeader4}) + Me.ListView2.Font = New System.Drawing.Font("微軟正黑體", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) + Me.ListView2.ForeColor = System.Drawing.SystemColors.WindowText + Me.ListView2.FullRowSelect = True + Me.ListView2.GridLines = True + Me.ListView2.HideSelection = False + Me.ListView2.Location = New System.Drawing.Point(268, 22) + Me.ListView2.MultiSelect = False + Me.ListView2.Name = "ListView2" + Me.ListView2.Size = New System.Drawing.Size(250, 286) + Me.ListView2.TabIndex = 12 + Me.ListView2.TileSize = New System.Drawing.Size(64, 64) + Me.ListView2.UseCompatibleStateImageBehavior = False + Me.ListView2.View = System.Windows.Forms.View.Details + ' + 'ColumnHeader3 + ' + Me.ColumnHeader3.Text = "ChannelName" + Me.ColumnHeader3.Width = 240 + ' + 'ColumnHeader4 + ' + Me.ColumnHeader4.Text = "Id" + Me.ColumnHeader4.Width = 1 + ' + 'Button1 + ' + Me.Button1.Enabled = False + Me.Button1.Font = New System.Drawing.Font("微軟正黑體", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) + Me.Button1.Location = New System.Drawing.Point(524, 244) + Me.Button1.Name = "Button1" + Me.Button1.Size = New System.Drawing.Size(115, 64) + Me.Button1.TabIndex = 13 + Me.Button1.Text = "選擇所選取的" + Me.Button1.UseVisualStyleBackColor = True + ' + 'BackgroundWorker_GetChannel + ' + ' + 'SelectServer_Channel + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(652, 349) + Me.Controls.Add(Me.Button1) + Me.Controls.Add(Me.ListView2) + Me.Controls.Add(Me.ListView1) + Me.Controls.Add(Me.StatusStrip1) + Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle + Me.Name = "SelectServer_Channel" + Me.Text = "SelectServer_Channel" + Me.StatusStrip1.ResumeLayout(False) + Me.StatusStrip1.PerformLayout() + Me.ResumeLayout(False) + + End Sub + + Friend WithEvents StatusStrip1 As StatusStrip + Friend WithEvents ToolStripProgressBar1 As ToolStripProgressBar + Friend WithEvents ImageList_Guilds As ImageList + Friend WithEvents BackgroundWorker1 As System.ComponentModel.BackgroundWorker + Friend WithEvents ListView1 As ListView + Friend WithEvents ColumnHeader1 As ColumnHeader + Friend WithEvents ColumnHeader2 As ColumnHeader + Friend WithEvents ListView2 As ListView + Friend WithEvents ColumnHeader3 As ColumnHeader + Friend WithEvents ColumnHeader4 As ColumnHeader + Friend WithEvents Button1 As Button + Friend WithEvents BackgroundWorker_GetChannel As System.ComponentModel.BackgroundWorker + Friend WithEvents BackgroundWorker_GETServerList As System.ComponentModel.BackgroundWorker +End Class diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.resx b/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.resx new file mode 100644 index 0000000..d99010c --- /dev/null +++ b/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 139, 17 + + + 331, 26 + + + 503, 26 + + + 742, 26 + + \ No newline at end of file diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.vb b/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.vb new file mode 100644 index 0000000..7d35e0c --- /dev/null +++ b/DiscordGameServersStatus/DiscordGameServersStatus/SelectServer_Channel.vb @@ -0,0 +1,171 @@ +Imports System.ComponentModel +Imports Discord +Imports Discord.WebSocket +Public Class SelectServer_Channel + + Dim selectGuild As String + Dim DC As DiscordSocketClient + Private Async Sub SelectServer_Channel_Load(sender As Object, e As EventArgs) Handles MyBase.Load + ToolStripProgressBar1.Style = ProgressBarStyle.Marquee + Try + DC = DGSS.DiscordClient + Await DC.LoginAsync(TokenType.Bot, My.Settings.token) + Await DC.StartAsync + DGSS.Start = True + Catch ex As Exception + + End Try + 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 + ToolStripProgressBar1.Style = ProgressBarStyle.Blocks + ToolStripProgressBar1.Value = vaule + Case 6 + ToolStripProgressBar1.Style = ProgressBarStyle.Blocks + ToolStripProgressBar1.Value = vaule + End Select + End If + End Sub + + Private Delegate Sub ServerListViewCallBack(ByVal item As ListViewItem) + Public Sub UpdateServerListView(ByVal item As ListViewItem) + If Me.InvokeRequired() Then + Dim cb As New ServerListViewCallBack(AddressOf UpdateServerListView) + Me.Invoke(cb, item) + Else + + ListView1.Items.Add(item) + + End If + End Sub + + Private Async Sub SelectServer_Channel_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing + + + End Sub + + Public Function GetImageFromURL(ByVal url As String) As Drawing.Image + + Dim retVal As Drawing.Image = Nothing + + Try + If Not String.IsNullOrWhiteSpace(url) Then + Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url.Trim) + + Using request As System.Net.WebResponse = req.GetResponse + Using stream As System.IO.Stream = request.GetResponseStream + retVal = New Bitmap(Drawing.Image.FromStream(stream)) + End Using + End Using + End If + Catch ex As Exception + MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", + vbCrLf, ex.Message), + "Exception Thrown", + MessageBoxButtons.OK, + MessageBoxIcon.Warning) + + End Try + + Return retVal + + End Function + + Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click + My.Settings.channel = ListView2.SelectedItems(0).SubItems(2).Text + My.Settings.dcServerID = ListView2.SelectedItems(0).SubItems(3).Text + My.Settings.Save() + DGSS.StartButton.PerformClick() + Me.Dispose() + End Sub + + Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork + Dim channels = DGSS.DiscordClient.GetGuild(sender.id) + End Sub + + + Dim selectGuids As New List(Of String) + Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged + selectGuids.Clear() + + + + For Each x As ListViewItem In ListView1.Items + If x.Selected Then + selectGuids.Add(x.SubItems(1).Text) + End If + Next + If selectGuids.Count <> 0 Then + ShowChannel() + Else + + End If + End Sub + + Private Sub ShowChannel() + + If Not BackgroundWorker_GETServerList.IsBusy Then + ListView2.Items.Clear() + BackgroundWorker_GetChannel.RunWorkerAsync() + End If + + End Sub + + Private Async Sub BackgroundWorker_GetChannel_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker_GetChannel.DoWork + + + For Each selectguid In selectGuids + Dim guidname = DC.GetGuild(selectguid).Name + Dim r = DC.GetGuild(selectguid).TextChannels + Dim numberToCompute As Int16 = r.Count + Dim k As Int16 = 1 + + For Each x As SocketTextChannel In r + + Dim item As New ListViewItem + item.Text = x.Name + item.SubItems.Add(guidname) + item.SubItems.Add(x.Id.ToString) + item.SubItems.Add(selectguid) + + UpdataUI(6, CInt((k / numberToCompute) * 100)) + k += 1 + UpdateChannelListView(item) + Next + + Next + + UpdataUI(6, 0) + + + End Sub + + Private Delegate Sub ChannelListViewCallBack(ByVal item As ListViewItem) + Private Sub UpdateChannelListView(ByVal item As ListViewItem) + If Me.InvokeRequired() Then + Dim cb As New ServerListViewCallBack(AddressOf UpdateChannelListView) + Me.Invoke(cb, item) + Else + + ListView2.Items.Add(item) + + End If + End Sub + + Private Sub ListView2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView2.SelectedIndexChanged + If ListView2.SelectedItems.Count <> 0 Then + + Button1.Enabled = True + End If + End Sub +End Class \ No newline at end of file diff --git a/DiscordGameServersStatus/DiscordGameServersStatus/packages.config b/DiscordGameServersStatus/DiscordGameServersStatus/packages.config index db41c0b..5575da0 100644 --- a/DiscordGameServersStatus/DiscordGameServersStatus/packages.config +++ b/DiscordGameServersStatus/DiscordGameServersStatus/packages.config @@ -14,7 +14,7 @@ - + @@ -52,6 +52,7 @@ +