Permalink
Browse files

Supresión de enlaces en la lista de spam y reintento en caso de falla

  • Loading branch information...
MarioFinale committed Mar 16, 2018
1 parent 799f039 commit 8cd391b917f381f37dc01eef2a05e9690f6f9458
Showing with 100 additions and 17 deletions.
  1. +38 −5 AddTopic.vb
  2. +1 −0 GlobalVars.vb
  3. +61 −12 Page.vb
@@ -18,35 +18,68 @@ Namespace WikiBot
Dim pagetext As String = "{{/Encabezado}}" & Environment.NewLine
Dim UpdateDate As Date = Date.UtcNow
Dim UpdateText As String = "<span style=""color:#0645AD"">►</span> Actualizado por " & BOTName & " al " & UpdateDate.ToString("dd 'de' MMMM 'de' yyyy 'a las' HH:mm '(UTC)'", New System.Globalization.CultureInfo("es-ES")) & " sobre un total de " & scannedPages.ToString & "páginas de archivo."
Dim TopicGroups As Dictionary(Of String, List(Of String)) = GetTopicGroups()
Dim EndList As New Dictionary(Of String, Dictionary(Of String, List(Of String))) 'Diccionario con (grupo,(tema, lineas()))
For Each t As String In topics.Keys
For Each tg As String In TopicGroups.Keys
If TopicGroups(tg).Contains(t) Then 'Si la lista del grupo contiene el tema
If Not EndList.Keys.Contains(tg) Then 'Si el grupo no esta en el diccionario final
EndList.Add(tg, New Dictionary(Of String, List(Of String))) 'Añade e inicializa el grupo
End If
If Not EndList(tg).Keys.Contains(t) Then 'Si el tema no está en el diccionario final
EndList(tg).Add(t, New List(Of String)) 'Añade e inicializa el tema
End If
EndList(tg)(t).AddRange(topics(t)) 'Añade las líneas al tema
End If
Next
Next
For Each g As String In EndList.Keys 'Por cada grupo en la lista
pagetext = pagetext & Environment.NewLine & "== " & g & "==" 'Añadir al texto el título
For Each t As String In EndList(g).Keys 'Por cada tema
pagetext = pagetext & Environment.NewLine & "=== " & t & " ==="
Next
Next
End Function
Function GetTopicGroups() As Dictionary(Of String, List(Of String))
Dim GroupsPage As Page = _bot.Getpage(TopicGroupsPage) 'Inicializar página de grupos
End Function
End Function
Function GetTopicGroups() As Dictionary(Of String, List(Of String))
Dim GroupsPage As Page = _bot.Getpage(TopicGroupsPage) 'Inicializar página de grupos
Dim Threads As String() = _bot.GetPageThreads(GroupsPage.Text) 'Obtener hilos de la página
Dim Groups As New Dictionary(Of String, List(Of String))
For Each t As String In Threads 'Por cada hilo...
Dim threadTitle As String = Regex.Match(t, "(\n|^)(==.+==)").Value.Trim.Trim("="c).Trim 'Obtiene el título del hilo
If Not Groups.Keys.Contains(threadTitle) Then 'Si el diccionario no contiene el título del hilo...
Groups.Add(threadTitle, New List(Of String)) 'Añade el hilo al diccionario
End If
For Each l As String In GetLines(t, True) 'Por cada línea en el hilo...
Dim top As String = l.Trim.Trim("*"c).Trim 'Eliminar los espacios en blanco y asteriscos al principio y al final
Groups(threadTitle).Add(top) 'Añadirlo a la clave en el diccionario
Next
Next
'Regresar el diccionario
Return Groups
End Function
Function GetTopicsText(Optional ByRef Inclusions As Integer = 0) As Dictionary(Of String, List(Of String))
@@ -33,6 +33,7 @@ Module GlobalVars
Public Const TopicPageName As String = "Wikipedia:Café por tema"
Public Const TopicTemplate As String = "Plantilla:Tema"
Public Const TopicGroupsPage As String = "Wikipedia:Café por tema/Grupos"
Public Const MaxRetry As Integer = 10
Public LogC As New LogEngine(Log_Filepath, User_Filepath)
Public Userdata As List(Of String()) = LogC.LogUserData
73 Page.vb
@@ -232,8 +232,17 @@ Namespace WikiBot
End Function
''' <summary>
''' Guarda la página en la wiki. Si la página no existe, la crea.
''' </summary>
''' <param name="text">Texto (wikicódigo) de la página</param>
''' <param name="EditSummary">Resumen de la edición</param>
''' <param name="IsMinor">¿Marcar como menor?</param>
''' <param name="Spamreplace">¿Reemplazar los link marcados como spam?</param>
''' <returns></returns>
Overloads Function Save(ByVal text As String, ByVal EditSummary As String, ByVal IsMinor As Boolean, ByVal IsBot As Boolean, ByVal SpamReplace As Boolean) As String
Return SavePage(text, EditSummary, IsMinor, IsBot, SpamReplace, 0)
End Function
''' <summary>
''' Guarda la página en la wiki. Si la página no existe, la crea.
@@ -242,7 +251,7 @@ Namespace WikiBot
''' <param name="EditSummary">Resumen de la edición</param>
''' <param name="IsMinor">¿Marcar como menor?</param>
''' <returns></returns>
Private Function SavePage(ByVal text As String, ByVal EditSummary As String, ByVal IsMinor As Boolean, ByVal IsBot As Boolean) As String
Private Overloads Function SavePage(ByVal text As String, ByVal EditSummary As String, ByVal IsMinor As Boolean, ByVal IsBot As Boolean, ByVal Spamreplace As Boolean, ByRef RetryCount As Integer) As String
If String.IsNullOrEmpty(text) Or String.IsNullOrWhiteSpace(text) Then
Throw New ArgumentNullException("Empty parameter", "Text")
End If
@@ -285,15 +294,55 @@ Namespace WikiBot
Return "Edit successful!"
End If
If postresult.Contains("abusefilter") Then
If postresult.ToLower.Contains("abusefilter") Then
Log("AbuseFilter Triggered! on " & _title, "LOCAL", BOTName)
Debug_Log("ABUSEFILTER: " & postresult, "BOT", BOTName)
Return "AbuseFilter"
End If
If postresult.ToLower.Contains("spamblacklist") Then
Log("AbuseFilter Triggered! on " & _title, "LOCAL", BOTName)
Debug_Log("ABUSEFILTER: " & postresult, "BOT", BOTName)
If Spamreplace Then
Dim spamlinkRegex As String = TextInBetween(postresult, """spamblacklist"":""", """")(0)
Dim newtext As String = Regex.Replace(text, RegexParser(spamlinkRegex), "es.wikipedia.org/wiki/Wikipedia:Spam")
If Not RetryCount > MaxRetry Then
Return SavePage(newtext, EditSummary, IsMinor, IsBot, True, RetryCount + 1)
Else
Log("Max retry count saving " & _title, "LOCAL", BOTName)
Return "Max retry count"
End If
Else
Return "SpamBlacklist"
End If
End If
'Unexpected result, retry
If Not RetryCount > MaxRetry Then
Return SavePage(text, EditSummary, IsMinor, IsBot, True, RetryCount + 1)
Else
Log("Max retry count saving " & _title, "LOCAL", BOTName)
Debug_Log("Unexpected saving result: " & postresult, "BOT", BOTName)
Return "Max retry count"
End If
Return "Unexpected result"
End Function
''' <summary>
''' Guarda la página en la wiki. Comprueba si la página tiene la plantilla {{nobots}}. Si la página no existe, la crea.
''' </summary>
''' <param name="text">Texto (wikicódigo) de la página</param>
''' <param name="Summary">Resumen de la edición</param>
''' <param name="IsMinor">¿Marcar como menor?</param>
''' <returns></returns>
Overloads Function CheckAndSave(ByVal text As String, ByVal summary As String, ByVal isMinor As Boolean, ByVal isBOT As Boolean, ByVal SpamReplace As Boolean) As String
If Not BotCanEdit(_text, _username) Then
Log("Bots can't edit " & _title & "!", "BOT", BOTName)
Return "No Bots"
End If
Return SavePage(text, summary, isMinor, isBOT, False, 0)
End Function
''' <summary>
''' Guarda la página en la wiki. Comprueba si la página tiene la plantilla {{nobots}}. Si la página no existe, la crea.
''' </summary>
@@ -306,7 +355,7 @@ Namespace WikiBot
Log("Bots can't edit " & _title & "!", "BOT", BOTName)
Return "No Bots"
End If
Return SavePage(text, summary, isMinor, isBOT)
Return SavePage(text, summary, isMinor, isBOT, False, 0)
End Function
''' <summary>
@@ -321,7 +370,7 @@ Namespace WikiBot
Log("Bots can't edit " & _title & "!", "BOT", BOTName)
Return "No Bots"
End If
Return SavePage(text, summary, isMinor, False)
Return SavePage(text, summary, isMinor, False, False, 0)
End Function
''' <summary>
@@ -335,7 +384,7 @@ Namespace WikiBot
Log("Bots can't edit " & _title & "!", "BOT", BOTName)
Return "No Bots"
End If
Return SavePage(text, summary, False, False)
Return SavePage(text, summary, False, False, False, 0)
End Function
''' <summary>
@@ -348,7 +397,7 @@ Namespace WikiBot
Log("Bots can't edit " & _title & "!", "BOT", BOTName)
Return "No Bots"
End If
Return SavePage(text, "Bot edit", False, False)
Return SavePage(text, "Bot edit", False, False, False, 0)
End Function
''' <summary>
@@ -359,7 +408,7 @@ Namespace WikiBot
''' <param name="IsMinor">¿Marcar como menor?</param>
''' <returns></returns>
Overloads Function Save(ByVal text As String, ByVal summary As String, ByVal isMinor As Boolean, ByVal isBOT As Boolean) As String
Return SavePage(text, summary, isMinor, isBOT)
Return SavePage(text, summary, isMinor, isBOT, False, 0)
End Function
@@ -371,7 +420,7 @@ Namespace WikiBot
''' <param name="IsMinor">¿Marcar como menor?</param>
''' <returns></returns>
Overloads Function Save(ByVal text As String, ByVal summary As String, ByVal isMinor As Boolean) As String
Return SavePage(text, summary, isMinor, False)
Return SavePage(text, summary, isMinor, False, False, 0)
End Function
''' <summary>
@@ -381,7 +430,7 @@ Namespace WikiBot
''' <param name="Summary">Resumen de la edición</param>
''' <returns></returns>
Overloads Function Save(ByVal text As String, ByVal summary As String) As String
Return SavePage(text, summary, False, False)
Return SavePage(text, summary, False, False, False, 0)
End Function
''' <summary>
@@ -390,7 +439,7 @@ Namespace WikiBot
''' <param name="text">Texto (wikicódigo) de la página</param>
''' <returns></returns>
Overloads Function Save(ByVal text As String) As String
Return SavePage(text, "Bot edit", False, False)
Return SavePage(text, "Bot edit", False, False, False, 0)
End Function
''' <summary>

0 comments on commit 8cd391b

Please sign in to comment.