'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Dim server As Server
Private domain As String="mydomain.duckdns.org"
Private token As String="mydomaintoken"
Private time ,update As Timer
Private tele As SMMTeleBot
Private smmtoken As String="telegrambottoken"
Private off As Long
Private allin As Map
Dim thum As String
End Sub
Sub AppStart (Args() As String)
allin.Initialize
tele.Initialize(smmtoken,"tg",10000,10000,10000)
tele.SetWebhookListener("127.0.0.1:8080","" , 40)
SetLoggingLevel("OFF")
time.Initialize("UpdateIp",1000*60*10)
server.Initialize("server")
server.Port=51051
server.Start
UpdateIp_Tick
StartMessageLoop
End Sub
Sub getUp_tick
tele.GetUpdatesList( off+1,1000,9000 )
Log("ticking and off = "&off)
End Sub
Sub tg_sent(m As Message)
Log("tg_sent"&m.chat.id)
Log("tg_sent"&m.messageId)
' If m.IsInitialized Then
If m.replyToMessage.IsInitialized Then
If m.replyToMessage.text.Length<3 Then
If m.replyToMessage.from.username="shujamu" Then
Log("here")
End If
Dim btn,btn2 As InlineKeyboardButton
btn.Initialize("good").callbackData("returnedthing")
btn2.Initialize("one"&"").callbackData("nothing")
Dim kk As InlineKeyboardMarkup
kk.Initialize(Array As InlineKeyboardButton(btn,btn2))
tele.sendMessage( m.chat.id,DateTime.Time(DateTime.Now), m.messageId ,"HTML",kk)
Log("tg_sent "&m)
End If
tele.DeleteMessage(m.chat.id ,m.messageId)
End If
' End If
End Sub
Sub tg_process(updates As List)
#IgnoreWarnings :7
If updates.IsInitialized Then
For up = 0 To updates.Size-1
Dim u As Update=updates.Get(up)
Log("Update: "&u)
If u.callbackQuery.IsInitialized Then
Dim callbackquer As CallbackQuery =u.callbackQuery
Log("Query Back is "&callbackquer)
Log(callbackquer.chatInstance)
If IsNumber(callbackquer.data) Then
End If
Log(callbackquer.from.id)
tele.sendMessage(callbackquer.from.id,DateTime.Time(DateTime.Now), -1 ,tele.PARSEMODE_MARKDOWN,Null)
Log(callbackquer.gameShortName)
Log(callbackquer.id)
Log(callbackquer.inlineMessageId)
Log(callbackquer.message)
tele.AnswerCallbackQuery(callbackquer.id,"","",False,1)
End If
If u.IsInitialized Then
off=u.updateId
If u.inlineQuery.IsInitialized Then
Log("u.inlineQuery")
Log("Inline query: "&u.inlineQuery.query)
Dim q As String =u.inlineQuery.query.Trim
If q.Length>0 Then
doload_article(q.Replace(" ","%20"),u.inlineQuery)
End If
End If
End If
If u.message.IsInitialized Then
If u.message.text<>Null Then
If u.message.replyToMessage.IsInitialized=True Then
Log(u.message.replyToMessage.from.username)
If u.message.replyToMessage.from.username="SMMtelebot" Then
Log("YES")
tele.EditMessageText( u.message.replyToMessage.chat.id,u.message.replyToMessage.messageId,"WAS edited",tele.PARSEMODE_HTML,False)
Else
Log("NO")
End If
End If
If u.updateId>= off Then
off=u.updateId
If u.message.text.Contains("butons") Then
Log(u.message.text)
Dim kbtn,kbtn2 As KeyboardButton
kbtn.Initialize("good"&"")
kbtn2.Initialize("one"&"\u26BD")
Dim g As ReplyKeyboardMarkup
g.Initialize(Array As String ("A","B","C")).oneTimeKeyboard(True).selective(False).resizeKeyboard(True)
tele.sendMessage2(u.message.chat.id ,"" , 0,tele.PARSEMODE_HTML, g)'
Else
Log("Not butons")
Dim btn,btn2,btn3 As InlineKeyboardButton
btn.Initialize("ClickMe").callbackData("returnedthing")
btn2.Initialize("Cancel").url("https://telegram.org").callbackData("callback_data")
btn3.Initialize("What?").callbackData("nothing")
tele.sendMessage( u.message.chat.id, "BotMessage here", 0 ,"HTML",tele.CreateInlineKeyboardMarkup(Array As InlineKeyboardButton (btn,btn2,btn3)))
End If
'
'
End If
End If
End If
Next
End If
End Sub
Sub doload_article(q As String,il As InlineQuery)
thum ="https://telegram.org/img/t_logo.png"
Dim j As HttpJob
j.Initialize("", Me)
j.Tag=il
Dim rul As String="https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts|pageimages&exintro=&explaintext=&titles="&q.Replace(" ","%20")
j.Download(rul)
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
Dim inline As InlineQuery=j.Tag
Dim art As InlineQueryResultArticle
Dim jsn As JSONParser
jsn.Initialize(j.GetString)
Log(j.GetString)
Dim jnmap As Map =jsn.NextObject
If jnmap.IsInitialized Then
Dim querymap As Map=jnmap.Get("query")
Dim pagesmap As Map=querymap.Get("pages")
Dim numbersmap As Map=pagesmap.Get(pagesmap.GetKeyAt(0))
For Each k In numbersmap.Keys
Log(k)
Next
Dim thing As String= ""
If numbersmap.ContainsKey("extract") Then
thing=numbersmap.Get("extract")
Log(numbersmap.Get("title"))
End If
If numbersmap.ContainsKey("thumbnail") Then
Dim thumbmap As Map =numbersmap.Get("thumbnail")
thum= thumbmap.Get("source")
End If
If thing.Length>0 Then
' Log("thing "&thing)
Dim title As String =thing'.SubString2(0,Min(thing.Length,10))
art.Initialize(inline.id,title ,thing.Replace(CRLF," "))
art.thumbUrl(thum)
Else
art.Initialize(inline.id, "Found nothing","Nothin)
art.thumbUrl(thum)
End If
Else
Log("Else")
art.Initialize(inline.id,thing,thing)
End If
tele.AnswerInlineQuery( inline,art , 3000,True ,"","", "" )
End If
j.Release
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub SetLoggingLevel(level As String)
' Log("Set Logging Level to " & level.ToUpperCase)
If level.Length = 0 Then Return
Dim joJ As JavaObject 'Jetty Object
Dim joP As JavaObject 'Properties Object
joP.InitializeNewInstance("java.util.Properties", Null)
joP.RunMethod("setProperty", Array("org.eclipse.jetty.LEVEL", level.ToUpperCase))
joJ.InitializeNewInstance("org.eclipse.jetty.util.log.StdErrLog", Array("JettyLog", joP))
End Sub
Sub UpdateIp_Tick
Log("UpdateIp_Tick")
Dim j As HttpJob
j.Initialize("j", Me)
j.Tag=Null
Try
j.Download2("http://www.duckdns.org/update", Array As String("domains", domain, "token", token, _
"ip", ""))
Catch
Log(LastException)
End Try
End Sub