wm: irc-h2o-bot

Download patch

ref: 564d4ac9075fba971a480d20ba59d2adc6a0e768
parent: 2eebe5d9f9511c34cb90bf6852d01c42a60a66c2
author: 0x4A4D00 <scorpion_rn@yahoo.com>
date: Wed Jul 19 13:06:33 EDT 2023

Multi Threading Updated - Test Needed

--- a/test.rb
+++ b/test.rb
@@ -3,7 +3,13 @@
 require 'net/http'
 require 'uri'
 require 'json'
+require 'concurrent'
 
+executor = Concurrent::ThreadPoolExecutor.new(
+  min_threads: 2,
+  max_threads: 5,
+  max_queue: 10
+)
 
 $irc = Net::YAIL.new(
   :address    => 'irc.ircnow.org',
@@ -12,7 +18,9 @@
   :nicknames  => ['h2o-bot0']
 )
 
+$currentid = ''
 
+
 $irc.on_welcome proc { |event| $irc.join('#fpc') }
 
 
@@ -75,16 +83,63 @@
   $irc.msg(peer, b)
 end
 
+$irc.heard_msg(:if => {:pm? => true}) do |e|
+  if ($currentid != e.nick)
+    $currentid = e.nick
+    puts($currentid)
+    SendReq(e.nick, e.message, $irc)
+    puts('e')
+  end
+end
 
+$irc.heard_msg(:if => {:pm? => false}) do |e|
+  if (e.message.start_with?("h2o") && $currentid != e.channel)
+    $currentid = e.channel
+    puts($currentid)
+    SendReq(e.channel, e.message, $irc)
+    puts('e')
+  end
+end
+$irc.start_listening!
+futures = []
+
+3.times do |i|
+  futures << Concurrent::Future.execute(executor: executor) do
+    $irc.heard_msg(:if => {:pm? => true}) do |e|
+      if ($currentid != e.nick)
+        $currentid = e.nick
+        puts($currentid)
+        SendReq(e.nick, e.message, $irc)
+        puts('e')
+      end
+    end
+
+    $irc.heard_msg(:if => {:pm? => false}) do |e|
+      if (e.message.start_with?("h2o") && $currentid != e.channel)
+        $currentid = e.channel
+        puts($currentid)
+        SendReq(e.channel, e.message, $irc)
+        puts('e')
+      end
+    end
+  end
+end
+
 def Tra
   $irc.heard_msg(:if => {:pm? => true}) do |e|
-    SendReq(e.nick, e.message, $irc)
+    if ($currentid != e.nick)
+      $currentid = e.nick
+      SendReq(e.nick, e.message, $irc)
+    end
+    $currentid = ''
   end
 
   $irc.heard_msg(:if => {:pm? => false}) do |e|
-    if (e.message.start_with?("h2o"))
+    if (e.message.start_with?("h2o") && $currentid != e.channel)
+      $currentid = e.channel
       SendReq(e.channel, e.message, $irc)
     end
+    $currentid = ''
   end
 end
 
@@ -112,13 +167,13 @@
   end
 end
 
-threads = []
-threads << Thread.new { Tra() }
-threads << Thread.new { Tra2() }
-threads << Thread.new { Tra3() }
+#threads = []
+#threads << Thread.new { Tra() }
+#threads << Thread.new { Tra() }
+#threads << Thread.new { Tra() }
 
 # Wait for all threads to complete
-threads.each(&:join)
+#threads.each(&:join)
 
 
 
@@ -128,7 +183,7 @@
 #
 # end
 
-$irc.start_listening!
+