Pārlūkot izejas kodu

moving watcher rules to their own file in config/ so bot is easier to customize

tags/v0.1
Ben Kurtovic pirms 13 gadiem
vecāks
revīzija
b5ce2fa675
4 mainītis faili ar 41 papildinājumiem un 23 dzēšanām
  1. +0
    -2
      config/irc.py
  2. +33
    -0
      config/watcher.py
  3. +1
    -1
      irc/rc.py
  4. +7
    -20
      irc/watcher.py

+ 0
- 2
config/irc.py Parādīt failu

@@ -19,8 +19,6 @@ REALNAME = "[[w:en:User:EarwigBot]]"

# channels to join on main server's startup
CHANS = ["##earwigbot", "##earwig", "#wikipedia-en-afc"]
AFC_CHANS = ["#wikipedia-en-afc"] # report recent AfC changes/give AfC status messages upon join
BOT_CHANS = ["##earwigbot", "#wikipedia-en-afc"] # report edits containing "!earwigbot"

# hardcoded hostnames of users with certain permissions
OWNERS = ["wikipedia/The-Earwig"] # can use owner-only commands (!restart and !git)


+ 33
- 0
config/watcher.py Parādīt failu

@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-

# EarwigBot Configuration File
# This file contains rules for the bot's watcher component.

import re

AFC_CHANS = ["#wikipedia-en-afc"] # report recent AfC changes/give AfC status messages upon join
BOT_CHANS = ["##earwigbot", "#wikipedia-en-afc"] # report edits containing "!earwigbot"

def process(rc):
chans = set() # channels to report this message to
page_name = rc.page.lower()
if "!earwigbot" in rc.msg.lower():
chans.update(BOT_CHANS)
if re.match("wikipedia( talk)?:(wikiproject )?articles for creation", page_name):
chans.update(AFC_CHANS)
elif re.match("wikipedia( talk)?:files for upload", page_name):
chans.update(AFC_CHANS)
elif page_name.startswith("template:afc submission"):
chans.update(AFC_CHANS)
elif rc.flags == "delete" and re.match("deleted \"\[\[wikipedia( talk)?:(wikiproject )?articles for creation", rc.comment.lower()):
chans.update(AFC_CHANS)
elif rc.flags == "protect" and re.match("protected \"\[\[wikipedia( talk)?:(wikiproject )?articles for creation", rc.comment.lower()):
chans.update(AFC_CHANS)

return chans

+ 1
- 1
irc/rc.py Parādīt failu

@@ -27,7 +27,7 @@ class RC:
self.page, self.flags, self.url, self.user, self.comment = page, flags, url, user, comment

def pretty(self):
def get_pretty(self):
"""make a nice, colorful message from self.msg to send to the front-end"""
pretty = self.msg
return pretty

+ 7
- 20
irc/watcher.py Parādīt failu

@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-

## Imports
import re

from config.irc import *
from config.watcher import *

from irc.connection import Connection
from irc.rc import RC
@@ -48,23 +47,11 @@ def main(connection, f_conn):
if line[1] == "376": # Join the recent changes channel when we've finished starting up
connection.join(WATCHER_CHAN)

def report(msg, chans):
"""send a message to a list of report channels on our front-end server"""
for chan in chans:
frontend_conn.say(chan, msg)

def check(rc):
"""check if we're supposed to report this message anywhere"""
page_name = rc.page.lower()
pretty_msg = rc.pretty()

if "!earwigbot" in rc.msg.lower():
report(pretty_msg, chans=BOT_CHANS)
if re.match("wikipedia( talk)?:(wikiproject )?articles for creation", page_name):
report(pretty_msg, chans=AFC_CHANS)
elif re.match("wikipedia( talk)?:files for upload", page_name):
report(pretty_msg, chans=AFC_CHANS)
elif page_name.startswith("template:afc submission"):
report(pretty_msg, chans=AFC_CHANS)
if rc.flags == "delete" and re.match("deleted \"\[\[wikipedia( talk)?:(wikiproject )?articles for creation", rc.comment.lower()):
report(pretty_msg, chans=AFC_CHANS)
results = process(rc) # process the message in config/watcher.py, and get a list of channels to send it to
if not results:
return
pretty = rc.get_pretty()
for chan in results:
frontend_conn.say(chan, pretty)

Notiek ielāde…
Atcelt
Saglabāt