Skip to content
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 3b32a63 + 7ee5935 commit 5215bfc3f3ff2f6b6c2b7342836dd7bc4e604779 @shogo82148 committed Apr 7, 2012
Showing with 30 additions and 12 deletions.
  1. +19 −5 JO_RI_bot.py
  2. +9 −5 TwitterBot/AdminFunctions.py
  3. +2 −2 TwitterBot/BaseBot.py
View
24 JO_RI_bot.py
@@ -24,7 +24,7 @@
class GlobalCloneBot(CloneBot):
def __init__(self, crawl_user, mecab=None, log_file='crawl.tsv', db_file='bigram.db', crawler_api=None):
super(GlobalCloneBot, self).__init__(crawl_user, mecab, log_file, db_file, crawler_api)
- self.translator = Translator(config.BING_APP_KEY, 'ja', 'en')
+ self.translator = Translator(config.BING_APP_KEY, 'ja', 'en').translator
def reply_hook(self, bot, status):
"""適当にリプライを返してあげる"""
@@ -63,10 +63,17 @@ def __init__(self):
reset_cycle = 20*60,
allowed_users = config.BOT_USER))
self.append_reply_hook(AdminFunctions.history_hook(
- reply_limit = config.REPLY_LIMIT,
- reset_cycle = config.RESET_CYCLE,
- limit_msg = u'今、ちょっと取り込んでまして・・・'
- u'またのご利用をお待ちしております!'))
+ reply_limit = config.REPLY_LIMIT1,
+ reset_cycle = config.RESET_CYCLE1,
+ limit_msg = [u'今、ちょっと取り込んでまして・・・'
+ u'またのご利用をお待ちしております!',
+ u'もっと時間を有意義に使いませんか?']))
+ self.append_reply_hook(AdminFunctions.history_hook(
+ reply_limit = config.REPLY_LIMIT2,
+ reset_cycle = config.RESET_CYCLE2,
+ limit_msg = [u'今、ちょっと取り込んでまして・・・'
+ u'またのご利用をお待ちしております!',
+ u'もっと時間を有意義に使いませんか?']))
self.append_reply_hook(JO_RI_bot.limit_hook)
self.translator = Translator(config.BING_APP_KEY)
@@ -114,6 +121,13 @@ def __init__(self):
self.append_cron('00 7-23 * * *',
self.clone_bot.update_status,
name=u'Cron Update Status')
+ self.append_cron('30 11 * * *',
+ self.bot_attack,
+ name=u'Cron Bot Attack')
+
+ def bot_attack(self, bot):
+ name = random.choice(['aokcub_bot', 'FUCOROID', 'aokcub_bot', 'FUCOROID', 'JO_RI'])
+ bot.update_status('@%s %s' % (name, self.clone_bot.get_text()))
def on_start(self):
self.clone_bot.crawl(self)
View
14 TwitterBot/AdminFunctions.py
@@ -4,6 +4,7 @@
import TwitterBot
import time
import datetime
+import random
class admin_hook(object):
"""特定ユーザしか実行できないコマンド"""
@@ -55,14 +56,14 @@ def __call__(self, bot, status):
return False
if self.is_allowed(status):
if status.in_reply_to_status_id:
- self.destroy_status(status.in_reply_to_status_id)
+ bot.destroy_status(status.in_reply_to_status_id)
elif self._no_in_reply:
- self.reply_to(u'%s [%s]' %
+ bot.reply_to(u'%s [%s]' %
(self._no_in_reply, bot.get_timestamp()) )
return True
if self._not_allowed:
- self.reply_to(u'%s [%s]' %
+ bot.reply_to(u'%s [%s]' %
(self._not_allowed, bot.get_timestamp()) )
return False
@@ -100,8 +101,11 @@ def __call__(self, bot, status):
#履歴更新
if author in history:
if history[author]['count']==self.reply_limit and self.limit_msg:
- self.reply_to(u'%s [%s]' %
- (self.limit_msg, bot.get_timestamp()),
+ msg = self.limit_msg
+ if isinstance(msg, (list, tuple)):
+ msg = random.choice(msg)
+ bot.reply_to(u'%s [%s]' %
+ (msg, bot.get_timestamp()),
status)
history[author]['count'] += 1
if history[author]['count']>self.reply_limit:
View
4 TwitterBot/BaseBot.py
@@ -329,11 +329,11 @@ def get_timestamp(self):
return time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())
def update_status(self, status, *args, **kargs):
- logger.info(u'update:' + status)
+ logger.info(u'update: ' + status)
return self.api.update_status(status, *args, **kargs)
def destroy_status(self, status_id):
- logger.info(u'delete:' + status_id)
+ logger.info(u'delete: %d' % int(status_id))
return self.api.destroy_status(status_id)
def reply_to(self, status, in_reply_to, cut=True):

0 comments on commit 5215bfc

Please sign in to comment.
Something went wrong with that request. Please try again.