I would like the bot to reply to me only as PM.
e.g. I send the bot as PM !say 1
Then the bot should only reply in PM 2.
But the bot only recognizes a message in the channel, not in the PM.
Private Async Function onMessage(message As SocketMessage) As Task
Dim user = TryCast(message.Author, SocketGuildUser)
If message.Source <> MessageSource.Bot And message.Content.StartsWith("!") Then
If message.Content.StartsWith("!say 1") And DirectCast(message.Author, SocketGuildUser).Roles.ToList.Contains(DirectCast(message.Channel, IGuildChannel).Guild.GetRole(91586140315277)) Then
Await message.Channel.SendMessageAsync("2")
Await user.SendMessageAsync("2")
End If
End If
End Function
Related
I want to control RadioState of Wifi and Mobile(cellular) connection in Windows 10 x64 using custom application written in VB. It works for Wifi radio but doesn't for MobileBroadband.
Actually code does the same job as click on ActionCenter in Windows 10 and press Wifi or Cellular button.
Private Async Sub TurnMobileOnOff(arg As Integer)
Dim access = Await Windows.Devices.WiFi.WiFiAdapter.RequestAccessAsync
Dim radios = Await Windows.Devices.Radios.Radio.GetRadiosAsync
If access = Windows.Devices.WiFi.WiFiAccessStatus.Allowed Then
For Each radio In radios
If radio.Kind = Windows.Devices.Radios.RadioKind.MobileBroadband Then
If arg = 1 Then
Await radio.SetStateAsync(Windows.Devices.Radios.RadioState.On)
RichTextBox1.AppendText(vbCrLf & "Mobile connection is turninng on")
ElseIf arg = 0 Then
Await radio.SetStateAsync(Windows.Devices.Radios.RadioState.Off)
RichTextBox1.AppendText(vbCrLf & "Mobile connection is turninng off")
End If
End If
Next
End If
End Sub
There's no error message, just radiostate is unchanged. The same code works for WiFi as expected.
Source:https://learn.microsoft.com/en-us/uwp/api/windows.devices.radios.radiostate
Thank for any help.
I'm trying to make a bot that sends a private message when triggered by a specific word.
For example, it would trigger if I type 'send_me_dm'
After the bot sends me a dm message, if I were to dm back 'hiiii", the bot will reply in the dm 'hi'
My code :
If message.Content.Contains("send_me_dm") Then
Dim user = TryCast(message.Author, SocketGuildUser)
Await user.SendMessageAsync("you can talk with me") 'now it send as dm
End If
Dim channell As SocketTextChannel = discord.GetChannel(message.Channel.Id)
If message.Channel.Id.Equals(channell) Then
If message.Content.Contains("hiiii") Then
Await channell.SendMessageAsync("hi")
End If
End If
I use this code to send an email using SMTP
Dim clnt As New System.Net.Mail.SmtpClient
clnt.UseDefaultCredentials = False
clnt = New System.Net.Mail.SmtpClient(gate)
Dim auth_info As System.Net.NetworkCredential = New System.Net.NetworkCredential(toAddress, pass)
'// MESSAGE SETUP
Dim msg As New System.Net.Mail.MailMessage(fromAddress, toAddress)
If msg.To.Count = 0 Then Return False
msg.CC.Clear()
'// SEND A COPY TO SENDER
'msg.Bcc.Add(auth_info.UserName)
msg.Bcc.Add(fromAddress)
'msg.DeliveryNotificationOptions = Net.Mail.DeliveryNotificationOptions.OnFailure
'msg.DeliveryNotificationOptions = Net.Mail.DeliveryNotificationOptions.OnSuccess
msg.Headers.Add("Disposition-Notification-To", fromAddress)
msg.Subject = subject
msg.Body = msgbody
msg.IsBodyHtml = True
Dim serverBusy As Boolean = True
While serverBusy
Try
clnt.Send(msg)
serverBusy = False
Catch
serverBusy = True
End Try
End While
With this code the copy of the email is sent to the sender because
of the bcc property, but in the 'incoming folder'.
Because of headers property I achieve to be informed if the receiver
read the message. A dialog box asks the receiver if he wants the
sender to be informed that he read the email message, If he
presses OK then the sender is informed with a new message. The
problem is that with this implementation the sender is asked with
the same dialog box when he opens the the copy of the message(bcc
property).
I have ...
Private Sub TestTask()
Debug.Write("Running")
For i As Integer = 0 To 60
Debug.Write(".")
System.Threading.Thread.Sleep(1000)
Next
Debug.WriteLine("Finished")
End Sub
....
Dim cts As New CancellationTokenSource
Dim oToken As CancellationToken = cts.Token
'Create HelperTask to wait for cancellation request
Dim oHelperTask As Task = Task.Factory.StartNew(Function()
'Create Task to invoke function
Dim oTask As Task = Task.Factory.StartNew(Function()
Return outerFunction.Invoke
End Function, oToken)
' wait for cancellation token if Task is not complete
While oTask.Status = TaskStatus.Running
Thread.Sleep(200)
If oToken.IsCancellationRequested Then
oToken.ThrowIfCancellationRequested()
Return Nothing
End If
End While
Return oTask.Result
End Function, oToken)
cts.cancel()
But in my debug window on visual sudio my TestTask() continues to run with ..... please anyone enlighten me. Thanks
The whole point of the CancellationToken is that the actual worker lambda (or function) should check it to see if it should stop. In your case, TestTask must have access to the token and check it after each iteration. Neither the multiple helper tasks or the checks for the task status or the cancellation request check are necessary.
The MSDN article on Task Cancelation shows how the only thing required is for the lambda to check the token, nothing more.
In your case, TestTask can respond to a cancellation with code as simple as this:
Sub Main()
Dim cts As New CancellationTokenSource
Dim token = cts.Token
Task.Factory.StartNew(Sub() TestTask(token), token)
Thread.Sleep(3000)
cts.Cancel()
Console.ReadKey()
End Sub
Private Sub TestTask(token As CancellationToken)
Console.Write("Running")
For i As Integer = 0 To 60
token.ThrowIfCancellationRequested()
Console.Write(".")
Thread.Sleep(1000)
Next
Console.WriteLine("Finished")
End Sub
The only thing needed is to pass the token to TestTask and start it like this:
Task.Factory.StartNew(Sub() TestTask(token), token)
You don't want/need 2 tasks - it's cooperative cancellation, so every task you want to end when cancel is called will need to include ThrowIfCancellationRequested (or however it should handle cancellation). There's intentionally no Thread.Abort type behavior/semantics, it's all cooperative.
Could any body give me code how to send sms through GSM mobiles, connected with computer?
Thanks
Furqan
About one year ago I have used mCore library for this purpose.
It is very simple to use (if my VB.NET is correct):
Private objSMS As New mCore.SMS()
' Set up connection and check '
' if connection is open '
Private Sub SendSms()
If Not objSMS.IsConnected Then
objSMS.Port = "COM4"
objSMS.BaudRate = mCore.BaudRate.BaudRate_19200
objSMS.DataBits = mCore.DataBits.Eight
objSMS.Parity = mCore.Parity.None
objSMS.StopBits = mCore.StopBits.One
objSMS.FlowControl = mCore.FlowControl.None
objSMS.DisableCheckPIN = False
objSMS.Encoding = mCore.Encoding.Unicode_16Bit
End If
Dim strSendResult As String = objSMS.SendSMS("+7921XXXXXXX", "Server CORP_DB2 is down!", False)
End Sub
This library supports a lot of mobile phones and has a lot of useful functions: sending USSD requests, receiving incoming SMS and so on.
mCore is shareware but it has trial version. Trial version will add text to all SMSs that SMS sent by mCore.