twitter: start/stop mention poll thread via irc
includes a migration for a new permission for this, naturally. with this, the poll thread can be started and actually do stuff
This commit is contained in:
parent
3b78e9b894
commit
9d5b9e070b
|
@ -1,6 +1,7 @@
|
|||
"""Access to Twitter through bot commands."""
|
||||
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
import twython
|
||||
|
@ -49,6 +50,10 @@ class Twitter(Plugin):
|
|||
self.handle_auth, -20)
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!twitter\s+replyto\s+(\S+)\s+(.*)',
|
||||
self.handle_replyto, -20)
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!twitter\s+mentionpoll\s+start',
|
||||
self.handle_start_mentionpoll, -20)
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!twitter\s+mentionpoll\s+stop',
|
||||
self.handle_stop_mentionpoll, -20)
|
||||
|
||||
# try getting the stored auth tokens and logging in
|
||||
try:
|
||||
|
@ -80,11 +85,30 @@ class Twitter(Plugin):
|
|||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_gettoken)
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_auth)
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_replyto)
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_start_mentionpoll)
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_stop_mentionpoll)
|
||||
|
||||
self.poll_mentions = False
|
||||
|
||||
super(Twitter, self).stop()
|
||||
|
||||
def handle_start_mentionpoll(self, connection, event, match):
|
||||
if not has_permission(event.source, 'twitter.manage_threads'):
|
||||
return self.bot.reply(event, "You do not have permission to start/stop threads.")
|
||||
|
||||
self.poll_mentions = True
|
||||
t = threading.Thread(target=self.thread_watch_mentions)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
self.bot.reply(event, "Now polling for mentions.")
|
||||
|
||||
def handle_stop_mentionpoll(self, connection, event, match):
|
||||
if not has_permission(event.source, 'twitter.manage_threads'):
|
||||
return self.bot.reply(event, "You do not have permission to start/stop threads.")
|
||||
|
||||
self.poll_mentions = False
|
||||
self.bot.reply(event, "No longer polling for mentions.")
|
||||
|
||||
def handle_getstatus(self, connection, event, match):
|
||||
"""Get a status by tweet ID."""
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('twitter', '0005_replace_since_id_with_replies_specific_one'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='twitterclient',
|
||||
options={'permissions': (('send_tweets', 'Can send tweets via IRC'), ('manage_threads', 'Can start/stop polling threads via IRC'))},
|
||||
),
|
||||
]
|
|
@ -24,4 +24,5 @@ class TwitterClient(models.Model):
|
|||
class Meta:
|
||||
permissions = (
|
||||
('send_tweets', "Can send tweets via IRC"),
|
||||
('manage_threads', "Can start/stop polling threads via IRC"),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue