From bc3e7878cc7ce70ddf13f355f180f812a49aea82 Mon Sep 17 00:00:00 2001 From: cheveguerra Date: Sun, 24 Sep 2023 02:59:40 -0600 Subject: [PATCH] Ligas de Github. --- B4A/B4XMainPage.bas | 28 +++--- B4A/Mariana.b4a | 2 +- B4A/NotificationService.bas | 178 ++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 16 deletions(-) create mode 100644 B4A/NotificationService.bas diff --git a/B4A/B4XMainPage.bas b/B4A/B4XMainPage.bas index c478c3a..23848dc 100644 --- a/B4A/B4XMainPage.bas +++ b/B4A/B4XMainPage.bas @@ -6,23 +6,21 @@ Version=9.85 @EndOfDesignText@ #Region Shared Files #CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files" -'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True -'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip -'########################################################################################################### -'###################### PULL ############################################################# -'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=git&Args=pull -'########################################################################################################### -'###################### PUSH ############################################################# -'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=github&Args=..\..\ -'########################################################################################################### -'###################### PUSH TORTOISE GIT ######################################################### -'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=TortoiseGitProc&Args=/command:commit&Args=/path:"./../" -'########################################################################################################### + 'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True + 'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip + '########################################################################################################### + '###################### PULL ############################################################# + 'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=git&Args=pull + '########################################################################################################### + '###################### PUSH ############################################################# + 'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=github&Args=..\..\ + '########################################################################################################### + '###################### PUSH TORTOISE GIT ######################################################### + 'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=TortoiseGitProc&Args=/command:commit&Args=/path:"./../../"&Args=/closeonend:2 + '########################################################################################################### #End Region -'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=github&Args=..\..\ -'- Se modifico "Nota" para que cuando ya este guardado el pedido, ya no se puedan borrar los productos individuales. -'- Se agregó el servicio "NotificationService" para interceptar notificaciones y por medio de un mensaje de WhatsApp (#NS http://10.0.0.205:1782), cambiar el servidor de DBReq. +'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=github&Args=..\..\ Sub Class_Globals Private Root As B4XView diff --git a/B4A/Mariana.b4a b/B4A/Mariana.b4a index 32618c9..c88c5c6 100644 --- a/B4A/Mariana.b4a +++ b/B4A/Mariana.b4a @@ -750,7 +750,7 @@ Module9=C_NoVenta NumberOfFiles=347 NumberOfLibraries=26 NumberOfModules=26 -Version=12.2 +Version=12.5 @EndOfDesignText@ #Region Project Attributes #ApplicationLabel: Mariana diff --git a/B4A/NotificationService.bas b/B4A/NotificationService.bas new file mode 100644 index 0000000..27893f3 --- /dev/null +++ b/B4A/NotificationService.bas @@ -0,0 +1,178 @@ +B4A=true +Group=Default Group +ModulesStructureVersion=1 +Type=Service +Version=11 +@EndOfDesignText@ +#Region Service Attributes + #StartAtBoot: False +#End Region + +Sub Process_Globals + 'These global variables will be declared once when the application starts. + 'These variables can be accessed from all modules. + Dim rp As ReplyAuto +' Dim activo As Boolean = True +' Dim ultimaNoti As String + Dim logger As Boolean = False +End Sub + +Sub Service_Create + rp.Initialize("NotiMon") + #if not(DEBUG) + logger = False + #end if +' If logger Then Log("**************** Iniciamos Monitor Keymon ***********************") +End Sub + +Sub Service_Start (StartingIntent As Intent) +' Log("NotificationService Start") + If rp.HandleIntent(StartingIntent) Then Return +' DateTime.DateFormat = "mm" +' ultimaNoti = DateTime.Date(DateTime.now) +' If logger Then LogColor($"Ultima notificación en el minuto ${ultimaNoti}"$, Colors.green) +End Sub + +Sub Service_Destroy + +End Sub + +Sub NotiMon_NotificationPosted (SBN As StatusBarNotification) + Private logger As Boolean = True + If SBN.PackageName = "com.whatsapp" Then + If logger Then LogColor(SBN.PackageName, Colors.Red) + If logger Then LogColor("isGroupWA2: "&isGroupWA(SBN),Colors.Magenta) + If logger Then LogColor("isPersonWA: "&isPersonWA(SBN),Colors.Magenta) + If logger Then Log($"getGroupName: |${getGroupName(SBN.Title)}|"$) + Private cmd() As String = Regex.Split(" ", SBN.Message) + If SBN.Message.StartsWith("#NS") And cmd.Length = 2 Then 'Si el mensaje contiene "#NS" y tiene un segundo parametro ... + If esMensajeWAValido(SBN) Then +' Log(cmd(1)) + rp.ClearNotification(SBN) + Starter.reinicializaReqManager(cmd(1)) + rp.reply(SBN.Notification, SBN.PackageName, $"Servidor cambiado a ${cmd(1)} "$) + Sleep(1000) +' rp.ClearNotification(SBN) + rp.ClearAll + End If + End If + End If +End Sub + +'Regresa verdadero si el mensaje de whatsapp es un mensaje valido. +Sub esMensajeWAValido(SBN As StatusBarNotification) + Private valido As Boolean = False + Private ww() As String = Regex.Split("\|", SBN.Key) + If ww(3) <> Null And ww(3) <> "null" Then valido = True + Return valido +End Sub + +'Returns TRUE if the sender is a GROUP. +'Searches the provided sbn.title for the string ": " to know if the sender is a group. +Sub isGroupWA2(sbnTitle As String) As Boolean 'ignore + Private x As Boolean = Regex.ismatch(".*(: ).*", sbnTitle) + Return x +End Sub + +'Returns TRUE if the sender is a GROUP. +'Searches the provided notification object for the string "@g.us" and if found returns TRUE. +Sub isGroupWA(sbn As StatusBarNotification) As Boolean + Private a As Boolean = False + If sbn.As(String).IndexOf("@g.us") > -1 Then a = True 'ignore + Return a +End Sub + +'Returns TRUE if the sender is a PERSON. +'Searches the provided notification object for the string "@s.whatsapp.net" and if found returns TRUE. +Sub isPersonWA(sbn As StatusBarNotification) As Boolean 'ignore + Private a As Boolean = False + If sbn.As(String).IndexOf("@s.whatsapp.net") > -1 Then a = True 'ignore + Return a +End Sub + +'Returns TRUE if the sender is a PERSON. +'Searches the provided notification object for the string "channel=individual" and if found returns TRUE. +Sub isPersonWA2(sbn As StatusBarNotification) As Boolean 'ignore + Private a As Boolean = False + If sbn.As(String).IndexOf("channel=individual") > -1 Then a = True 'ignore + Return a +End Sub + +'Returns the sender's number. +'Searches the provided notification object and gets the numbers between "shortcut=" and "@s.whatsapp.net". +Sub getNumberWA(sbn As StatusBarNotification) As String + Private a As Int = sbn.As(String).IndexOf("@s.whatsapp.net") 'ignore + If a > -1 Then + Private x As String = sbn.As(String) 'ignore + Private y As Int = x.IndexOf("shortcut=") + If (y+9) > 0 And a > (y+9) Then x = x.SubString2(y+9, a) Else x = "Not a person" + Else 'It is probably is a group. + x = "Not a person" + End If + Return x +End Sub + +'Returns the name of the group from the given text. +'If it is not a group, then returns the notification's title. +Sub getGroupName(sbnTitle As String) As String 'ignore + Private a As Int = sbnTitle.IndexOf(": ") + Private x As String = sbnTitle + If a > -1 Then + Private b As String = sbnTitle.SubString2(0, a) + x = Regex.Replace(" \(.+\)", b, "") + End If + Return x +End Sub + +'Returns the name of the group from the given notification object. +'Searches the provided notification for the string "hiddenConversationTitle" and if found, gets the name. +'If it is not a group,then it returns the notification's title. +Sub getGroupName2(sbn As StatusBarNotification) As String 'ignore + Private inicio As Int = sbn.Extras.As(String).IndexOf("hiddenConversationTitle=") 'ignore + If inicio > -1 And sbn.Extras.As(String).IndexOf("hiddenConversationTitle=null") = -1 Then 'ignore + Private x As String = sbn.Extras.As(String) 'ignore + Private fin As Int = x.IndexOf(", android.reduced.images=") + x = x.SubString2(inicio+24, fin) + x = Regex.Replace(" \(.+\)", x, "") 'Replace anything between () with "", this en the case that we have something like "MyGroupName (5 messages)" + Else 'Is not from a group. + Private x As String = sbn.Title + End If + Return x +End Sub + +'Returns the person's name (or the number) when the message comes from a group. +'Searches the provided sbn.title for the string ": " in the title and returns the string after that, +'if it does not find ": " then returns the complete string. +Sub getPersonFromGroup(sbnTitle As String) As String 'ignore + Private a As Int = sbnTitle.IndexOf(": ") + If a = -1 Then a = -2 'Is not from a group. + Private b As String = sbnTitle.SubString(a+2) + Return b +End Sub + +'Returns the NUMBER of the sender and if NOT a person, then returns the name of the group. +Sub getNumberOrGroupWA(sbn As StatusBarNotification) As String 'ignore + Private numRemitente As String = getNumberWA(sbn) + If numRemitente = "Not a person" Then numRemitente = getGroupName(sbn.Title) + Return numRemitente +End Sub + +'Regresa el "shortcut" del remitente. +'Si es de un grupo, es algo como "120363023512345678@g.us" +'Si es de una persona, entonces "5215512345678@s.whatsapp.net" +Sub getShortcut(sbn As StatusBarNotification) As String 'ignore + Private ap As Int = sbn.As(String).IndexOf("@s.whatsapp.net") 'ignore + Private ag As Int = sbn.As(String).IndexOf("@g.us") 'ignore + Private x As String = sbn.As(String) 'ignore + Private y As Int = x.IndexOf("shortcut=") + If ap > -1 Then + Private x As String = sbn.As(String) 'ignore + Private y As Int = x.IndexOf("shortcut=") + x = x.SubString2(y+9, ap+15) + Else if ag > -1 Then 'It is probably is a group. + Private x As String = sbn.As(String) 'ignore + Private y As Int = x.IndexOf("shortcut=") + x = x.SubString2(y+9, ag+5) + End If + Return x +End Sub \ No newline at end of file