Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 16.85 KB | None | 0 0
  1. Imports AIMLbot
  2. Imports MSNPSharp
  3. Imports System.Threading
  4. Imports System.ComponentModel
  5. Imports System.Runtime.InteropServices
  6.  
  7. Public Class handler_form
  8.     <DllImport("user32.dll", SetLastError:=True)> Private Shared Function LockWorkStation() As <MarshalAs(UnmanagedType.Bool)> Boolean
  9.     End Function
  10.     Dim master_contact As String = "scoutzknivez@hotmail.com"
  11.  
  12.     Private _conversations As New List(Of Conversation)(0)
  13.     Private _messenger As Messenger = Nothing
  14.     Private _firstInvitedContact As Contact = Nothing
  15.  
  16.     Dim text_message As New TextMessage
  17.  
  18.     Private nextPing As Integer = 60
  19.     Private rquoteSender
  20.     Private rquoteTimer As System.Threading.Timer
  21.  
  22.     Dim billy_bot_running As Integer = 0
  23.     Dim reverse_running As Integer = 0
  24.     Dim rquote_running As Integer = 0
  25.     Dim hotpotato_running As Integer = 0
  26.  
  27.     Private myBot As Bot
  28.     Private myUser As User
  29.     Private lastRequest As Request = Nothing
  30.     Private lastResult As Result = Nothing
  31.  
  32.     Public Sub New(ByVal conversation As Conversation, ByVal messenger As Messenger, ByVal contact As Contact)
  33.         InitializeComponent()
  34.  
  35.         myBot = New Bot()
  36.         myBot.loadSettings()
  37.         myUser = New User("Dejima", Me.myBot)
  38.         Dim loader As New AIMLbot.Utils.AIMLLoader(Me.myBot)
  39.         Me.myBot.isAcceptingUserInput = False
  40.         loader.loadAIML(Me.myBot.PathToAIML)
  41.         Me.myBot.isAcceptingUserInput = True
  42.  
  43.         If contact Is Nothing AndAlso conversation.Contacts.Count > 0 Then
  44.             ' Received nudge :(
  45.             'MsgBox("nudge")
  46.             'contact = conversation.Contacts(0)
  47.         End If
  48.  
  49.         'txt.Text = "Hi! :)"
  50.         'conversation.SendTextMessage(txt)
  51.  
  52.         AddEvent(conversation)
  53.  
  54.         _messenger = messenger
  55.  
  56.         _firstInvitedContact = contact
  57.         Try
  58.             Me.myUser.Predicates.loadSettings(My.Computer.FileSystem.CurrentDirectory + "\users\" + _firstInvitedContact.Mail + ".xml")
  59.         Catch ex As Exception
  60.             Me.myUser.Predicates.DictionaryAsXML.Save(My.Computer.FileSystem.CurrentDirectory + "\users\" + _firstInvitedContact.Mail + ".xml")
  61.         End Try
  62.  
  63.     End Sub
  64.  
  65.     Private Sub processInputFromUser(ByVal contact, ByVal message)
  66.         If Me.myBot.isAcceptingUserInput Then
  67.             Dim rawInput As String = message.text
  68.             Dim myRequest As New Request(rawInput, Me.myUser, Me.myBot)
  69.             Dim myResult As Result = Me.myBot.Chat(myRequest)
  70.             Me.lastRequest = myRequest
  71.             Me.lastResult = myResult
  72.             text_message.Text = myResult.Output
  73.             ActiveConversation.SendTypingMessage()
  74.             ActiveConversation.SendTextMessage(text_message)
  75.             End If
  76.     End Sub
  77.  
  78.     Public Sub AttachConversation(ByVal convers As Conversation)
  79.         AddEvent(convers)
  80.     End Sub
  81.     Public ReadOnly Property ActiveConversation As Conversation
  82.         Get
  83.             Return GetActiveConversation()
  84.         End Get
  85.     End Property
  86.     Private Function GetActiveConversation() As Conversation
  87.         For Each conversation As Conversation In _conversations
  88.             If Not conversation.Ended Then
  89.                 Return conversation
  90.             End If
  91.         Next
  92.         If (_conversations.Count > 0) Then
  93.             Return _conversations(0)
  94.         End If
  95.         Dim newActiveConversation As Conversation = _messenger.CreateConversation
  96.         newActiveConversation.Invite(_firstInvitedContact)
  97.         _conversations.Add(newActiveConversation)
  98.         Return newActiveConversation
  99.     End Function
  100.     Public Function CanAttach(ByVal newconvers As Conversation) As Boolean
  101.         Return newconvers.HasContact(_firstInvitedContact)
  102.     End Function
  103.     Private Sub AddEvent(ByVal converse As Conversation)
  104.         If _conversations.Contains(converse) Then
  105.             Return
  106.         End If
  107.         'RemoveEvent(converse)
  108.         AddHandler converse.TextMessageReceived, AddressOf TextMessageReceived
  109.         AddHandler converse.ConversationEnded, AddressOf ConversationEnded
  110.         _conversations.Add(converse)
  111.         'AddHandler converse.SessionClosed, AddressOf SessionClosed
  112.         'AddHandler converse.ContactJoined, AddressOf ContactJoined
  113.         'AddHandler converse.ContactLeft, AddressOf Me.ContactLeft
  114.         'AddHandler converse.MSNObjectDataTransferCompleted, AddressOf Me.MSNObjectDataTransferCompleted
  115.         'Conversation.ConversationEnded += new EventHandler<ConversationEndEventArgs>(Conversation_ConversationEnded);
  116.  
  117.     End Sub
  118.     Private Sub TextMessageReceived(ByVal sender As Object, ByVal e As TextMessageEventArgs)
  119.         If billy_bot_running <> 0 Then
  120.             Select Case billy_bot_running
  121.                 Case "1"
  122.                     'Billy bot is on question 1
  123.                     If e.Message.Text.Contains("14") Or e.Message.Text.ToLower().Contains("forteen") Then
  124.                         text_message.Text = e.Sender.Name + " is correct!"
  125.                         ActiveConversation.SendTypingMessage()
  126.                         ActiveConversation.SendTextMessage(text_message)
  127.                         text_message.Text = "Next question..."
  128.                         ActiveConversation.SendTypingMessage()
  129.                         ActiveConversation.SendTextMessage(text_message)
  130.                         billy_bot_running += 1
  131.                         billy_bot()
  132.                     End If
  133.                 Case "2"
  134.                     'Billy bot is on question 2
  135.                     If e.Message.Text.ToLower().Contains("english") Then
  136.                         text_message.Text = e.Sender.Name + " is correct!"
  137.                         ActiveConversation.SendTypingMessage()
  138.                         ActiveConversation.SendTextMessage(text_message)
  139.                         text_message.Text = "Next question..."
  140.                         ActiveConversation.SendTypingMessage()
  141.                         ActiveConversation.SendTextMessage(text_message)
  142.                         billy_bot_running += 1
  143.                         billy_bot()
  144.                     End If
  145.                 Case "3"
  146.                     'Billy bot is on question 3
  147.                     If e.Message.Text.ToLower().Contains("true") Then
  148.                         text_message.Text = e.Sender.Name + " is correct!"
  149.                         ActiveConversation.SendTypingMessage()
  150.                         ActiveConversation.SendTextMessage(text_message)
  151.                         text_message.Text = "Next question..."
  152.                         ActiveConversation.SendTypingMessage()
  153.                         ActiveConversation.SendTextMessage(text_message)
  154.                         billy_bot_running += 1
  155.                         billy_bot()
  156.                     End If
  157.                 Case Else
  158.                     billy_bot()
  159.                     'Tf? Negative.
  160.             End Select
  161.             Exit Sub
  162.         End If
  163.         Select Case True
  164.             Case e.Message.Text.StartsWith(".msg")
  165.                 master_message(e.Sender, e.Message)
  166.         End Select
  167.         Select Case e.Message.Text.ToLower
  168.             Case "!roll"
  169.                 Dim RandomClass As New Random()
  170.                 text_message.Text = RandomClass.Next(1, 100).ToString()
  171.                 ActiveConversation.SendTextMessage(text_message)
  172.             Case "!billybot".ToLower
  173.                 billy_bot()
  174.             Case "!at"
  175.                 If rquote_running = 1 Then
  176.                     rquote_running = 0
  177.                     rquoteTimer.Dispose()
  178.                 Else
  179.                     rquote_running = 1
  180.                     rquoteSender = sender
  181.                     Dim rquoteCallback As New TimerCallback(AddressOf randomQuote_Line_Tick)
  182.                     rquoteTimer = New System.Threading.Timer(rquoteCallback, Nothing, 1000, 1000)
  183.                 End If
  184.             Case "!reverse"
  185.                 If reverse_running = 1 Then
  186.                     reverse_running = 0
  187.                 Else
  188.                     reverse_running = 1
  189.                 End If
  190.             Case "!spin".ToLower
  191.                 spin_thebottle(e.Sender)
  192.             Case "!hp".ToLower
  193.                 hot_potato(e.Sender)
  194.             Case "!throw".ToLower
  195.                 throw_potato(e.Sender)
  196.             Case "!shutdown"
  197.                 System.Diagnostics.Process.Start("shutdown", "-s -t 00")
  198.             Case "!help"
  199.                 text_message.Text = "List of available commands: !at, !billybot, !help, !hp, !spin, !roll, !reverse"
  200.                 ActiveConversation.SendTypingMessage()
  201.                 ActiveConversation.SendTextMessage(text_message)
  202.             Case "!lock"
  203.                 If e.Sender.Mail = "scoutzknivez@hotmail.com" Then
  204.                     If Not LockWorkStation() Then
  205.                         Throw New Win32Exception()
  206.                     End If
  207.                 End If
  208.             Case Else
  209.                 'Reverse message
  210.                 processInputFromUser(e.Sender, e.Message)
  211.                 If reverse_running = 1 Then
  212.                     Dim input As String = e.Message.Text.ToString()
  213.                     Dim output As String = ""
  214.                     Dim CharStr As New Char
  215.                     For Each CharStr In input
  216.                         output = CharStr & output
  217.                     Next
  218.                     text_message.Text = output
  219.                     ActiveConversation.SendTextMessage(text_message)
  220.                 End If
  221.         End Select
  222.     End Sub
  223.     Private Sub randomQuote_Line_Tick()
  224.         Dim handler As SBMessageHandler = TryCast(rquoteSender, SBMessageHandler)
  225.         If nextPing > 0 Then
  226.             nextPing -= 1
  227.             Dim RandomClass As New Random()
  228.             Dim next_duetime = RandomClass.Next(0, 35)
  229.             nextPing = next_duetime
  230.         End If
  231.         If nextPing = 0 Then
  232.             Dim RandomClass As New Random()
  233.             Dim random = RandomClass.Next(1, 13)
  234.             random = RandomClass.Next(1, 13)
  235.             Select Case random
  236.                 Case 1
  237.                     text_message.Text = "Well, this is awkward..."
  238.                 Case 2
  239.                     text_message.Text = "Burp."
  240.                 Case 3
  241.                     text_message.Text = "Bark!"
  242.                 Case 4
  243.                     text_message.Text = "Let's !roll ;D"
  244.                 Case 5
  245.                     text_message.Text = "Leave me alone :("
  246.                 Case 6
  247.                     text_message.Text = "Well, this is awkward..."
  248.                 Case 7
  249.                     text_message.Text = "Wait, what?"
  250.                 Case 8
  251.                     text_message.Text = "(H)"
  252.                 Case 9
  253.                     text_message.Text = "^o) Seriously?"
  254.                 Case 10
  255.                     text_message.Text = "Ugh, no.... Just.. No."
  256.                 Case 11
  257.                     text_message.Text = "Did I stutter?"
  258.                 Case 12
  259.                     text_message.Text = "Ah, did you see what I just did there? ;D"
  260.             End Select
  261.             ActiveConversation.SendTypingMessage()
  262.             ActiveConversation.SendTextMessage(text_message)
  263.             nextPing += 2000
  264.         End If
  265.     End Sub
  266.     Private Sub ContactJoined(ByVal sender As Object, ByVal e As ContactEventArgs)
  267.         'ActiveConversation.Contacts.Add(e.Contact)
  268.  
  269.     End Sub
  270.  
  271.     Private Sub NudgeReceived(ByVal sender As Object, ByVal e As ContactEventArgs)
  272.         ActiveConversation.SendNudge()
  273.     End Sub
  274.  
  275.     Private Sub hot_potato(ByVal owner)
  276.         Dim RandomClass As New Random()
  277.         Dim bottle_rand = RandomClass.Next(1, 4)
  278.         Dim potatoed_contact
  279.         Do
  280.             For Each c As Contact In ActiveConversation.Contacts
  281.                 potatoed_contact = c
  282.                 If ActiveConversation.Contacts.Count = 1 Then
  283.                     Exit Do
  284.                 End If
  285.                 If bottle_rand = 1 Then
  286.                     If potatoed_contact <> owner Then
  287.                         Exit Do
  288.                     End If
  289.                 Else
  290.                     bottle_rand = RandomClass.Next(1, 4)
  291.                 End If
  292.             Next
  293.         Loop
  294.         text_message.Text = "Ow! This potato is hot, here " + potatoed_contact.name + ", catch!"
  295.         ActiveConversation.SendTypingMessage()
  296.         ActiveConversation.SendTextMessage(text_message)
  297.         text_message.Text = "Type !throw to pass it around."
  298.         ActiveConversation.SendTypingMessage()
  299.         ActiveConversation.SendTextMessage(text_message)
  300.     End Sub
  301.  
  302.     Private Sub throw_potato(ByVal owner)
  303.         Dim RandomClass As New Random()
  304.         Dim bottle_rand = RandomClass.Next(1, 4)
  305.         Dim potatoed_contact
  306.         Do
  307.             For Each c As Contact In ActiveConversation.Contacts
  308.                 If bottle_rand = 1 Then
  309.                     potatoed_contact = c
  310.                     If ActiveConversation.Contacts.Count = 1 Then
  311.                         Exit Do
  312.                     End If
  313.                     If potatoed_contact <> owner Then
  314.                         Exit Do
  315.                     End If
  316.                 Else
  317.                     bottle_rand = RandomClass.Next(1, 4)
  318.                 End If
  319.             Next
  320.         Loop
  321.         text_message.Text = potatoed_contact.name + " has the potato! Quick, throw it away!"
  322.         ActiveConversation.SendTypingMessage()
  323.         ActiveConversation.SendTextMessage(text_message)
  324.     End Sub
  325.  
  326.     Private Sub spin_thebottle(ByVal owner)
  327.         text_message.Text = "Spinning the bottle!"
  328.         ActiveConversation.SendTypingMessage()
  329.         ActiveConversation.SendTextMessage(text_message)
  330.         Thread.Sleep(2000)
  331.         Dim RandomClass As New Random()
  332.         Dim potatoed_contact
  333.         Dim bottle_rand = RandomClass.Next(1, 4)
  334.         Do
  335.             For Each c As Contact In ActiveConversation.Contacts
  336.                 If bottle_rand = 1 Then
  337.                     potatoed_contact = c
  338.                     Exit Do
  339.                 Else
  340.                     bottle_rand = RandomClass.Next(1, 4)
  341.                 End If
  342.             Next
  343.         Loop
  344.         text_message.Text = "The bottle landed on " + potatoed_contact.name + "!" 'OKAY CONTACT, GOOGLE THIS
  345.         ActiveConversation.SendTypingMessage()
  346.         ActiveConversation.SendTextMessage(text_message)
  347.     End Sub
  348.     Private Sub billy_bot()
  349.         If billy_bot_running = 0 Then
  350.             text_message.Text = "Starting billybot, loading useless facts about the cold war..."
  351.             ActiveConversation.SendTypingMessage()
  352.             ActiveConversation.SendTextMessage(text_message)
  353.             billy_bot_running += 1
  354.         End If
  355.         Thread.Sleep(2000)
  356.         text_message.Text = "Question " + billy_bot_running.ToString() + "!"
  357.         ActiveConversation.SendTypingMessage()
  358.         ActiveConversation.SendTextMessage(text_message)
  359.         Select Case billy_bot_running
  360.             Case "1"
  361.                 'Billy bot is on question 1
  362.                 text_message.Text = "How far can a dolphin ejaculate?"
  363.             Case "2"
  364.                 'Billy bot is on question 2
  365.                 text_message.Text = "What is a French Kiss known as in France?"
  366.             Case "3"
  367.                 'Billy bot is on question 3
  368.                 text_message.Text = "True or False? Right handed people live, on average, nine years longer than left-handed people"
  369.             Case Else
  370.                 text_message.Text = "End of quiz, gg life"
  371.                 billy_bot_running = 0
  372.                 'Tf? Negative.
  373.         End Select
  374.         ActiveConversation.SendTypingMessage()
  375.         ActiveConversation.SendTextMessage(text_message)
  376.     End Sub
  377.  
  378.     Private Sub master_message(ByVal contact, ByVal message)
  379.         If contact.mail = "scoutzknivez@hotmail.com" Then
  380.             Dim mess_trim = message.text.ToString().Replace(".msg ", "")
  381.             Dim mess_index = mess_trim.IndexOf(" ")
  382.             Dim mess_contact = mess_trim.Substring(0, mess_index)
  383.             Dim mess_msg = mess_trim.Substring(mess_index + 1)
  384.             text_message.Text = mess_msg
  385.             text_message.CustomNickname = mess_contact
  386.             ActiveConversation.SendTypingMessage()
  387.             ActiveConversation.SendTextMessage(text_message)
  388.         End If
  389.     End Sub
  390.  
  391.     Private Sub ConversationEnded(ByVal sender As Object, ByVal e As ConversationEndEventArgs)
  392.         Try
  393.             Me.myUser.Predicates.DictionaryAsXML.Save(My.Computer.FileSystem.CurrentDirectory + "\users\" + _firstInvitedContact.Mail + ".xml")
  394.         Catch ex As Exception
  395.         End Try
  396.         Try
  397.             RemoveEvent(e.Conversation)
  398.             Me.Dispose()
  399.         Catch ex As Exception
  400.         End Try
  401.     End Sub
  402.  
  403.     Private Sub RemoveEvent(ByVal converse As Conversation)
  404.         RemoveHandler converse.TextMessageReceived, AddressOf TextMessageReceived
  405.         RemoveHandler converse.ConversationEnded, AddressOf ConversationEnded
  406.     End Sub
  407. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement