Repository: sopel-irc/sopel

Issue:
wikipedia: may trigger other Sopel instances
Reported by `sloopy` in IRC. bot2-. uses prefix `.` and bot1-# uses `#`

```
<sloopy> .w Star Trek
<bot2-.> [WIKIPEDIA] Star Trek | "Star Trek is an American science fiction entertainment franchise created by Gene Roddenberry and owned by CBS and Paramount Pictures. The television series Star Trek: The Original Series, Star Trek: The Animated Series, Star Trek: The Next Generation, Star Trek: Deep Space Nine, Star Trek: Voyager, Star..." | https://en.wikipedia.org/wiki/Star_Trek
<bot1-#> [WIKIPEDIA] Star Trek | "Star Trek is an American science fiction entertainment franchise created by Gene Roddenberry and owned by CBS and Paramount Pictures. The television series Star Trek: The Original Series, Star Trek: The Animated Series, Star Trek: The Next Generation, Star Trek: Deep Space Nine, Star Trek: Voyager, Star..."
```



Discussion:
@maxpowa Any special scenario to re-produce this bug? I  don't see this behaviour. Am i missing something? 

@psachin Running two instances of sopel with different prefixes in the same channel. The second bot is triggering on the URL that the first outputs. We prevent this in url.py but unfortunately have not in other modules that spit out urls.

Fixing this or not requires a decision on whether running multiple instances of Sopel in the same channel is a supported use case. I'm not sure it's worth adding code in various places to prevent one Sopel bot from triggering others, because there will always be other bot frameworks that would trigger anyway.

This sort of thing is best solved by adding all bots in a channel to each other's ignore/block lists, IMO.

Resolving patch:
diff --git a/sopel/modules/wikipedia.py b/sopel/modules/wikipedia.py
--- a/sopel/modules/wikipedia.py
+++ b/sopel/modules/wikipedia.py
@@ -61,7 +61,7 @@ def mw_search(server, query, num):
         return None
 
 
-def say_snippet(bot, server, query, show_url=True):
+def say_snippet(bot, trigger, server, query, show_url=True):
     page_name = query.replace('_', ' ')
     query = quote(query.replace(' ', '_'))
     try:
@@ -71,8 +71,11 @@ def say_snippet(bot, server, query, show_url=True):
             bot.say("[WIKIPEDIA] Error fetching snippet for \"{}\".".format(page_name))
         return
     msg = '[WIKIPEDIA] {} | "{}"'.format(page_name, snippet)
+    msg_url = msg + ' | https://{}/wiki/{}'.format(server, query)
+    if msg_url == trigger:  # prevents triggering on another instance of Sopel
+        return
     if show_url:
-        msg = msg + ' | https://{}/wiki/{}'.format(server, query)
+        msg = msg_url
     bot.say(msg)
 
 
@@ -102,7 +105,7 @@ def mw_info(bot, trigger, found_match=None):
     server.
     """
     match = found_match or trigger
-    say_snippet(bot, match.group(1), unquote(match.group(2)), show_url=False)
+    say_snippet(bot, trigger, match.group(1), unquote(match.group(2)), show_url=False)
 
 
 @commands('w', 'wiki', 'wik')
@@ -138,4 +141,4 @@ def wikipedia(bot, trigger):
         return NOLIMIT
     else:
         query = query[0]
-    say_snippet(bot, server, query)
+    say_snippet(bot, trigger, server, query)


Test patch: