From fe98e9f54982ae90d94784f0210c7d2688da1961 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 29 Jan 2016 22:14:33 +0000 Subject: [PATCH 01/20] announcements: odd fixes --- tipbot/modules/announcements.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tipbot/modules/announcements.py b/tipbot/modules/announcements.py index 5a24804..9d46dfc 100644 --- a/tipbot/modules/announcements.py +++ b/tipbot/modules/announcements.py @@ -29,7 +29,8 @@ def Announce(link,cmd): return nextid=redis_get('cryptokingdom:announcements:nextid') if nextid==None: - nextid=0 + nextid=1 + nextid=long(nextid) text = " ".join(cmd[1:]) redis_hset('cryptokingdom:announcements',nextid,'From %s: %s'%(link.user.nick,text)) nextid+=1 @@ -54,8 +55,8 @@ def Cancel(link,cmd): redis_hdel('cryptokingdom:announcements',which) def Help(link): - link.send(link,'Announce anything that you want others to know') - link.send(link,'Offers, auctions, other information') + link.send_private('Announce anything that you want others to know') + link.send_private('Offers, auctions, other information') From 2d324d6415c90e6135e492d67351e008db963139 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Wed, 8 Jun 2016 21:22:00 +0100 Subject: [PATCH 02/20] Allow integrated addresses --- tipbot/coinspecs.py | 2 +- tipbot/utils.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tipbot/coinspecs.py b/tipbot/coinspecs.py index 9d5170b..a6c0b76 100644 --- a/tipbot/coinspecs.py +++ b/tipbot/coinspecs.py @@ -15,7 +15,7 @@ coinspecs = { "symbol": "XMR", "atomic_units": 1e12, "denominations": [[1000000, 1, "piconero"], [1000000000, 1e6, "micronero"], [1000000000000, 1e9, "millinero"]], - "address_length": [95, 95], # min/max size of addresses + "address_length": [[95, 95], [106, 106]], # min/max size of addresses "address_prefix": ['4', '9'], # allowed prefixes of addresses "min_withdrawal_fee": 10000000000, "web_wallet_url": "https://mymonero.com/", # None is there's none diff --git a/tipbot/utils.py b/tipbot/utils.py index 2a6015b..b1f3ec0 100644 --- a/tipbot/utils.py +++ b/tipbot/utils.py @@ -76,8 +76,18 @@ def GetIdentityFromPaymentID(p): identity = "freenode:"+identity return identity +def IsAddressLengthValid(address): + if type(coinspecs.address_length[0]) == list: + for allist in coinspecs.address_length: + if len(address) >= allist[0] and len(address) <= allist[1]: + return True + else: + if len(address) >= coinspecs.address_length[0] and len(address) <= coinspecs.address_length[1]: + return True + return False + def IsValidAddress(address): - if len(address) < coinspecs.address_length[0] or len(address) > coinspecs.address_length[1]: + if not IsAddressLengthValid(address): return False for prefix in coinspecs.address_prefix: if address.startswith(prefix): From 95cda869287fa6a7bf1405d0acdb62df1a7286b0 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Wed, 8 Jun 2016 21:22:14 +0100 Subject: [PATCH 03/20] irc: do not busy wait when EOS from IRC --- tipbot/modules/irc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tipbot/modules/irc.py b/tipbot/modules/irc.py index 4a45655..183862f 100644 --- a/tipbot/modules/irc.py +++ b/tipbot/modules/irc.py @@ -443,6 +443,8 @@ class IRCNetwork(Network): (r,w,x)=select.select([self.irc.fileno()],[],[],1) if self.irc.fileno() in r: newdata=self._irc_recv(4096,socket.MSG_DONTWAIT) + if len(newdata) == 0: + raise RuntimeError('0 bytes received, EOF') else: newdata = None if self.irc.fileno() in x: From c8470260f083d32466398c80149e3c271ec17c07 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 3 Jul 2015 23:10:36 +0100 Subject: [PATCH 04/20] Add a message event --- tipbot/modules/irc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tipbot/modules/irc.py b/tipbot/modules/irc.py index 183862f..b420aad 100644 --- a/tipbot/modules/irc.py +++ b/tipbot/modules/irc.py @@ -314,6 +314,8 @@ class IRCNetwork(Network): self.update_last_active_time(chan,GetNick(who)) # resplit to avoid splitting text that contains ':' text = data.split(' :',1)[1] + if self.on_event: + self.on_event('message',link=Link(self,User(self,GetNick(who)),Group(self,chan)),message=text) exidx = text.find('!') if exidx != -1 and len(text)>exidx+1 and text[exidx+1] in string.ascii_letters and self.is_acceptable_command_prefix(text[:exidx]): cmd = text.split('!')[1] From 79bc336ebbaa02c54a5cd657ce6150c19fa4a5ee Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 5 Aug 2016 16:43:00 +0100 Subject: [PATCH 05/20] user: add ident --- tipbot/user.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tipbot/user.py b/tipbot/user.py index 9f1881f..d846607 100644 --- a/tipbot/user.py +++ b/tipbot/user.py @@ -10,9 +10,10 @@ # class User: - def __init__(self,network,nick): + def __init__(self,network,nick,ident=None): self.network=network self.nick=nick + self.ident=ident def check_registered(self): pass From fb5e80f7aa916f7f500af3be89a393780c4f6640 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 5 Aug 2016 16:43:18 +0100 Subject: [PATCH 06/20] irc: add ident to user-joined and message events --- tipbot/modules/irc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tipbot/modules/irc.py b/tipbot/modules/irc.py index b420aad..7ce4fe1 100644 --- a/tipbot/modules/irc.py +++ b/tipbot/modules/irc.py @@ -315,7 +315,7 @@ class IRCNetwork(Network): # resplit to avoid splitting text that contains ':' text = data.split(' :',1)[1] if self.on_event: - self.on_event('message',link=Link(self,User(self,GetNick(who)),Group(self,chan)),message=text) + self.on_event('message',link=Link(self,User(self,GetNick(who),who),Group(self,chan)),message=text) exidx = text.find('!') if exidx != -1 and len(text)>exidx+1 and text[exidx+1] in string.ascii_letters and self.is_acceptable_command_prefix(text[:exidx]): cmd = text.split('!')[1] @@ -340,7 +340,7 @@ class IRCNetwork(Network): self.userstable[chan][nick] = None log_log("New list of users in %s: %s" % (chan, str(self.userstable[chan].keys()))) if self.on_event: - self.on_event('user-joined',link=Link(self,User(self,nick),Group(self,chan))) + self.on_event('user-joined',link=Link(self,User(self,nick,who),Group(self,chan))) elif action == 'PART': nick = GetNick(who) From 82510c0f8870788ac54af2fb8edb04cf7e98f1e0 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 5 Aug 2016 16:43:39 +0100 Subject: [PATCH 07/20] spammer: new module to kickban some spamming scammer --- tipbot/modules/spammer.py | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tipbot/modules/spammer.py diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py new file mode 100644 index 0000000..cf4e6c2 --- /dev/null +++ b/tipbot/modules/spammer.py @@ -0,0 +1,82 @@ +#!/bin/python +# +# Cryptonote tipbot - matylda commands +# Copyright 2014, 2015 moneromooo +# +# The Cryptonote tipbot is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation; either version 2, or (at your option) +# any later version. +# + +import sys +import redis +import string +import re +import tipbot.config as config +from tipbot.log import log_error, log_warn, log_info, log_log +import tipbot.coinspecs as coinspecs +from tipbot.utils import * +from tipbot.user import User +from tipbot.link import Link +from tipbot.redisdb import * +from tipbot.command_manager import * + +def Ban(link): + log_info('Banning %s (%s)' % (link.user.nick, link.user.ident)) + if not link.group: + return + chan=link.group.name + log_info("chan: " + chan) + net=link.network + try: + cmd="MODE " + chan + " +b " + link.user.ident + net._irc_sendmsg(cmd) + cmd="KICK " + chan + " " + link.user.nick + net._irc_sendmsg(cmd) + cmd="MODE " + chan + " -b " + link.user.ident + net._irc_sendmsg(cmd) + except: + pass + +def OnUserJoined(event,*args,**kwargs): + link=kwargs['link'] + + nick=link.user.nick.lower() + if nick=="lbft" or nick=="lbft_": + Ban(link) + +def OnMessage(event,*args,**kwargs): + line=kwargs['message'] + if not line: + return + + line=re.sub(r'\x03[0-9]?[0-9]?','',line) + line=re.sub(r'\x0f','',line) + line=line.lower().strip() + + log_info("Testing: " + line) + for expr in ["astounding!", "triple your btc!", "pm me to begin!", "hatt uu"]: + if re.match(expr+".*",line): + link=kwargs['link'] + Ban(link) + return + +def Help(link): + link.send_private('Ban assholes') + + +RegisterModule({ + 'name': __name__, + 'help': Help, +}) +RegisterEventHandler({ + 'module': __name__, + 'event': 'user-joined', + 'function': OnUserJoined, +}) +RegisterEventHandler({ + 'module': __name__, + 'event': 'message', + 'function': OnMessage, +}) From 14be174cb6dba38c924d000ab0ba84888fcc1078 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 5 Aug 2016 16:49:29 +0100 Subject: [PATCH 08/20] spammer: Allow exprs to be in the middle --- tipbot/modules/spammer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index cf4e6c2..f27b3b7 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -57,7 +57,7 @@ def OnMessage(event,*args,**kwargs): log_info("Testing: " + line) for expr in ["astounding!", "triple your btc!", "pm me to begin!", "hatt uu"]: - if re.match(expr+".*",line): + if re.match(.*+expr+".*",line): link=kwargs['link'] Ban(link) return From b290f4a20f754b881bce9a7c392cf83c231d1292 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 5 Aug 2016 19:33:52 +0100 Subject: [PATCH 09/20] spammer: add more triggers --- tipbot/modules/spammer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index f27b3b7..e9cb607 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -56,8 +56,12 @@ def OnMessage(event,*args,**kwargs): line=line.lower().strip() log_info("Testing: " + line) - for expr in ["astounding!", "triple your btc!", "pm me to begin!", "hatt uu"]: - if re.match(.*+expr+".*",line): + for expr in [ + "astounding!", "triple your btc", "pm me to begin", "hatt uu", + "accelerate the blockchain", "u stappid", "me a message to begin", + "the ops have confirmed", "expanding technology", "exploding technology" + ]: + if re.match(".*"+expr+".*",line): link=kwargs['link'] Ban(link) return From 97b43c5af38d5ebdba27d9dfab5e5eddab779ff8 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Sat, 13 Aug 2016 18:59:06 +0100 Subject: [PATCH 10/20] spammer: remove the debug auto unban Don't want to make it too easy for the spammer --- tipbot/modules/spammer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index e9cb607..f27b2a5 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -34,8 +34,6 @@ def Ban(link): net._irc_sendmsg(cmd) cmd="KICK " + chan + " " + link.user.nick net._irc_sendmsg(cmd) - cmd="MODE " + chan + " -b " + link.user.ident - net._irc_sendmsg(cmd) except: pass From 29f6f1fdaa627c8579e4b88587edf953ace136e6 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Thu, 18 Aug 2016 22:24:04 +0100 Subject: [PATCH 11/20] spammer: triggers don't have to be lowercase anymore Also add "allah is doing" --- tipbot/modules/spammer.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index f27b2a5..72205ea 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -44,6 +44,13 @@ def OnUserJoined(event,*args,**kwargs): if nick=="lbft" or nick=="lbft_": Ban(link) +triggers=[l.lower() for l in [ + "astounding!", "triple your btc", "pm me to begin", "hatt uu", + "accelerate the blockchain", "u stappid", "me a message to begin", + "the ops have confirmed", "expanding technology", "exploding technology", + "allah is doing" +]] + def OnMessage(event,*args,**kwargs): line=kwargs['message'] if not line: @@ -54,11 +61,7 @@ def OnMessage(event,*args,**kwargs): line=line.lower().strip() log_info("Testing: " + line) - for expr in [ - "astounding!", "triple your btc", "pm me to begin", "hatt uu", - "accelerate the blockchain", "u stappid", "me a message to begin", - "the ops have confirmed", "expanding technology", "exploding technology" - ]: + for expr in triggers: if re.match(".*"+expr+".*",line): link=kwargs['link'] Ban(link) From 59bba001305d15d21ecb4310c5fa7d8014dfe95d Mon Sep 17 00:00:00 2001 From: moneromooo Date: Mon, 28 Nov 2016 19:28:55 +0000 Subject: [PATCH 12/20] Add some more spam/scam triggers --- tipbot/modules/spammer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index 72205ea..b62b5b9 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -48,7 +48,7 @@ triggers=[l.lower() for l in [ "astounding!", "triple your btc", "pm me to begin", "hatt uu", "accelerate the blockchain", "u stappid", "me a message to begin", "the ops have confirmed", "expanding technology", "exploding technology", - "allah is doing" + "allah is doing", "pm me to get going", "defragment the blockchain to grow" ]] def OnMessage(event,*args,**kwargs): From e387fa67abbc022bf39f312661ec021bc8a30266 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Mon, 28 Nov 2016 19:38:46 +0000 Subject: [PATCH 13/20] spammer: add show_triggers and add_trigger admin commands --- tipbot/modules/spammer.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index b62b5b9..6c0dcb8 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -67,6 +67,12 @@ def OnMessage(event,*args,**kwargs): Ban(link) return +def AddTrigger(link,cmd): + triggers.append(" ".join(cmd[1:])) + +def ShowTriggers(link,cmd): + link.send(", ".join(triggers)) + def Help(link): link.send_private('Ban assholes') @@ -85,3 +91,17 @@ RegisterEventHandler({ 'event': 'message', 'function': OnMessage, }) +RegisterCommand({ + 'module': __name__, + 'name': 'add_trigger', + 'function': AddTrigger, + 'admin': True, + 'help': "add keyword trigger to spammer trap" +}) +RegisterCommand({ + 'module': __name__, + 'name': 'show_triggers', + 'function': ShowTriggers, + 'admin': True, + 'help': "list keyword triggers" +}) From 921212d217a092680df56cabe83c3843175149f1 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Thu, 22 Dec 2016 11:50:32 +0000 Subject: [PATCH 14/20] New randompid command, to allow avoiding payment id reuse --- tipbot/modules/payment.py | 13 ++++++++++++- tipbot/utils.py | 9 ++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tipbot/modules/payment.py b/tipbot/modules/payment.py index f6d91e8..432624f 100644 --- a/tipbot/modules/payment.py +++ b/tipbot/modules/payment.py @@ -161,6 +161,9 @@ def UpdateCoin(data): def Deposit(link,cmd): Help(link) +def RandomPaymentID(link,cmd): + link.send_private(" New payment ID: %s" % GetRandomPaymentID(link)) + def Help(link): GetAccount(link.identity()) link.send_private("You can send %s to your account:" % coinspecs.name); @@ -168,7 +171,8 @@ def Help(link): link.send_private(" Address: %s" % address) if config.openalias_address != None: link.send_private(" (or %s when using OpenAlias)" % config.openalias_address) - link.send_private(" Payment ID: %s" % GetPaymentID(link)) + link.send_private(" Main payment ID: %s" % GetPaymentID(link)) + link.send_private(" OR generate random payment ids at will with: !randompid") link.send_private("Incoming transactions are credited after %d confirmations" % config.payment_confirmations) RegisterModule({ @@ -182,4 +186,11 @@ RegisterCommand({ 'function': Deposit, 'help': "Show instructions about depositing %s" % coinspecs.name }) +RegisterCommand({ + 'module': __name__, + 'name': 'randompid', + 'function': RandomPaymentID, + 'registered': True, + 'help': "Generate a new random payment ID" +}) diff --git a/tipbot/utils.py b/tipbot/utils.py index b1f3ec0..8e74e37 100644 --- a/tipbot/utils.py +++ b/tipbot/utils.py @@ -17,6 +17,8 @@ import time import threading import math import string +import random +from Crypto.Random.random import getrandbits from decimal import * import tipbot.config as config import tipbot.coinspecs as coinspecs @@ -55,8 +57,10 @@ def GetParam(parms,idx): return parms[idx] return None -def GetPaymentID(link): +def GetPaymentID(link,random=False): salt="2u3g55bkwrui32fi3g4bGR$j5g4ugnujb-"+coinspecs.name+"-"; + if random: + salt = salt + "-" + str(time.time()) + "-" + str(getrandbits(128)) p = hashlib.sha256(salt+link.identity()).hexdigest(); try: redis_hset("paymentid",p,link.identity()) @@ -64,6 +68,9 @@ def GetPaymentID(link): log_error('GetPaymentID: failed to set payment ID for %s to redis: %s' % (link.identity(),str(e))) return p +def GetRandomPaymentID(link): + return GetPaymentID(link, True) + def GetIdentityFromPaymentID(p): if not redis_hexists("paymentid",p): log_log('PaymentID %s not found' % p) From e1f3acc16c540fd72151e98c0b9683f23b9164f6 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 23 Dec 2016 16:51:24 +0000 Subject: [PATCH 15/20] spammer: remove "astounding!" from the trigger list It's a bit too trigger happy, as reported by jwinterm --- tipbot/modules/spammer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index 6c0dcb8..c508c4e 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -45,7 +45,7 @@ def OnUserJoined(event,*args,**kwargs): Ban(link) triggers=[l.lower() for l in [ - "astounding!", "triple your btc", "pm me to begin", "hatt uu", + "triple your btc", "pm me to begin", "hatt uu", "accelerate the blockchain", "u stappid", "me a message to begin", "the ops have confirmed", "expanding technology", "exploding technology", "allah is doing", "pm me to get going", "defragment the blockchain to grow" From 7991428bf9c3c8c63f9bc288dca8d868b741f454 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Sun, 4 Jun 2017 16:19:28 +0100 Subject: [PATCH 16/20] spammer: mute instead of ban, and allow admins and relays --- tipbot/config.py.example | 1 + tipbot/modules/spammer.py | 71 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/tipbot/config.py.example b/tipbot/config.py.example index 5efbc8c..ceba4af 100644 --- a/tipbot/config.py.example +++ b/tipbot/config.py.example @@ -116,3 +116,4 @@ kitsune_max_loss = 35 # how much are we prepared to lose as a ratio of our current pot kitsune_max_loss_ratio = 0.1 +spammer_allowed = ['_Slack', '_Telegram', 'i2p-relay'] diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index c508c4e..d435710 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -22,7 +22,7 @@ from tipbot.link import Link from tipbot.redisdb import * from tipbot.command_manager import * -def Ban(link): +def BanUser(link): log_info('Banning %s (%s)' % (link.user.nick, link.user.ident)) if not link.group: return @@ -37,12 +37,25 @@ def Ban(link): except: pass +def MuteUser(link): + log_info('Muting %s (%s)' % (link.user.nick, link.user.ident)) + if not link.group: + return + chan=link.group.name + log_info("chan: " + chan) + net=link.network + try: + cmd="MODE " + chan + " +m " + link.user.ident + net._irc_sendmsg(cmd) + except: + pass + def OnUserJoined(event,*args,**kwargs): link=kwargs['link'] nick=link.user.nick.lower() if nick=="lbft" or nick=="lbft_": - Ban(link) + BanUser(link) triggers=[l.lower() for l in [ "triple your btc", "pm me to begin", "hatt uu", @@ -55,6 +68,11 @@ def OnMessage(event,*args,**kwargs): line=kwargs['message'] if not line: return + link=kwargs['link'] + if IsAdmin(link): + return + if link.nick in config.allowed: + return line=re.sub(r'\x03[0-9]?[0-9]?','',line) line=re.sub(r'\x0f','',line) @@ -63,8 +81,7 @@ def OnMessage(event,*args,**kwargs): log_info("Testing: " + line) for expr in triggers: if re.match(".*"+expr+".*",line): - link=kwargs['link'] - Ban(link) + MuteUser(link) return def AddTrigger(link,cmd): @@ -73,6 +90,38 @@ def AddTrigger(link,cmd): def ShowTriggers(link,cmd): link.send(", ".join(triggers)) +def Ban(link,cmd): + link.send("disabled") # need to ban by ident + return + + try: + who=cmd[1] + except Exception,e: + link.send("usage: ban ") + return + group=link.group + if not group: + link.send("Not in a channel") + return + l=Link(link.network,User(link.network,who),group) + BanUser(l) + +def Mute(link,cmd): + link.send("disabled") # need to mute by ident + return + + try: + who=cmd[1] + except Exception,e: + link.send("usage: mute ") + return + group=link.group + if not group: + link.send("Not in a channel") + return + l=Link(link.network,User(link.network,who),group) + MuteUser(l) + def Help(link): link.send_private('Ban assholes') @@ -105,3 +154,17 @@ RegisterCommand({ 'admin': True, 'help': "list keyword triggers" }) +RegisterCommand({ + 'module': __name__, + 'name': 'ban', + 'function': Ban, + 'admin': True, + 'help': "ban a user" +}) +RegisterCommand({ + 'module': __name__, + 'name': 'mute', + 'function': Mute, + 'admin': True, + 'help': "mute a user" +}) From da965ebc698b0c69ff039c02305022c616f137ef Mon Sep 17 00:00:00 2001 From: moneromooo Date: Sun, 25 Jun 2017 18:00:23 +0100 Subject: [PATCH 17/20] spammer: silence with +q, not +m, remove telegram from exceptions Thanks iDunk for +q pointer --- tipbot/config.py.example | 2 +- tipbot/modules/spammer.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tipbot/config.py.example b/tipbot/config.py.example index ceba4af..fec0fb4 100644 --- a/tipbot/config.py.example +++ b/tipbot/config.py.example @@ -116,4 +116,4 @@ kitsune_max_loss = 35 # how much are we prepared to lose as a ratio of our current pot kitsune_max_loss_ratio = 0.1 -spammer_allowed = ['_Slack', '_Telegram', 'i2p-relay'] +spammer_allowed = ['_Slack', 'i2p-relay'] diff --git a/tipbot/modules/spammer.py b/tipbot/modules/spammer.py index d435710..237f364 100644 --- a/tipbot/modules/spammer.py +++ b/tipbot/modules/spammer.py @@ -45,7 +45,7 @@ def MuteUser(link): log_info("chan: " + chan) net=link.network try: - cmd="MODE " + chan + " +m " + link.user.ident + cmd="MODE " + chan + " +q " + link.user.ident net._irc_sendmsg(cmd) except: pass From ab6a2d60eba1842e3544e33e7e29e3ca0b3751b2 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Thu, 14 Sep 2017 10:33:56 +0100 Subject: [PATCH 18/20] Make RPC timeout configurable, and longer by default --- tipbot/config.py.example | 1 + tipbot/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tipbot/config.py.example b/tipbot/config.py.example index fec0fb4..0d8cf2e 100644 --- a/tipbot/config.py.example +++ b/tipbot/config.py.example @@ -28,6 +28,7 @@ payment_confirmations = 6 tipbot_balance_cache_time = 35 # seconds site_game_salt = '' openalias_address = None +rpc_timeout = 180 admins = ["freenode:moneromooo", "freenode:moneromoo"] diff --git a/tipbot/utils.py b/tipbot/utils.py index 8e74e37..30300a2 100644 --- a/tipbot/utils.py +++ b/tipbot/utils.py @@ -215,7 +215,7 @@ def StringToUnits(s): def SendJSONRPCCommand(host,port,method,params): try: - http = httplib.HTTPConnection(host,port,timeout=20) + http = httplib.HTTPConnection(host,port,timeout=config.rpc_timeout) except Exception,e: log_error('SendJSONRPCCommand: Error connecting to %s:%u: %s' % (host, port, str(e))) raise @@ -252,7 +252,7 @@ def SendJSONRPCCommand(host,port,method,params): def SendHTMLCommand(host,port,method): try: - http = httplib.HTTPConnection(host,port,timeout=20) + http = httplib.HTTPConnection(host,port,timeout=config.rpc_timeout) except Exception,e: log_error('SendHTMLCommand: Error connecting to %s:%u: %s' % (host, port, str(e))) raise From 55905122fb7c48c57b74aba3a50554c53166460b Mon Sep 17 00:00:00 2001 From: moneromooo Date: Sat, 30 Sep 2017 09:26:14 +0100 Subject: [PATCH 19/20] payment: more explicit wording about payment it --- tipbot/modules/payment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tipbot/modules/payment.py b/tipbot/modules/payment.py index 432624f..3e4c208 100644 --- a/tipbot/modules/payment.py +++ b/tipbot/modules/payment.py @@ -166,12 +166,12 @@ def RandomPaymentID(link,cmd): def Help(link): GetAccount(link.identity()) - link.send_private("You can send %s to your account:" % coinspecs.name); + link.send_private("You can send %s to your account using this address AND payment ID:" % coinspecs.name); address=GetTipbotAddress() or 'ERROR' link.send_private(" Address: %s" % address) if config.openalias_address != None: link.send_private(" (or %s when using OpenAlias)" % config.openalias_address) - link.send_private(" Main payment ID: %s" % GetPaymentID(link)) + link.send_private(" Use your primary payment ID: %s" % GetPaymentID(link)) link.send_private(" OR generate random payment ids at will with: !randompid") link.send_private("Incoming transactions are credited after %d confirmations" % config.payment_confirmations) From 08691aadbb3cd0b6ee607d06c7da644e73c5d27e Mon Sep 17 00:00:00 2001 From: moneromooo Date: Thu, 19 Oct 2017 21:44:03 +0100 Subject: [PATCH 20/20] Port to newer praw Obviously, everything changed in various ways and the doc was useless --- tipbot/modules/reddit.py | 67 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/tipbot/modules/reddit.py b/tipbot/modules/reddit.py index 38c75c1..f9b7a75 100644 --- a/tipbot/modules/reddit.py +++ b/tipbot/modules/reddit.py @@ -15,6 +15,7 @@ import time import threading import re import praw +import logging import tipbot.config as config from tipbot.log import log_error, log_warn, log_info, log_log from tipbot.user import User @@ -44,7 +45,7 @@ class RedditNetwork(Network): try: cfg=config.network_config[self.name] self.login=cfg['login'] - password=GetPassword(self.name) + password=GetPassword(self.name+'/password') self.subreddits=cfg['subreddits'] user_agent=cfg['user_agent'] self.update_period=cfg['update_period'] @@ -52,9 +53,19 @@ class RedditNetwork(Network): self.keyword=cfg['keyword'] self.use_unread_api=cfg['use_unread_api'] self.cache_timeout=cfg['cache_timeout'] + client_id=GetPassword(self.name+'/client_id') + client_secret=GetPassword(self.name+'/client_secret') + username=GetPassword(self.name+'/username') - self.reddit=praw.Reddit(user_agent=user_agent,cache_timeout=self.cache_timeout) - self.reddit.login(self.login,password) + if False: + handler = logging.StreamHandler() + handler.setLevel(logging.DEBUG) + logger = logging.getLogger('prawcore') + logger.setLevel(logging.DEBUG) + logger.addHandler(handler) + + self.reddit=praw.Reddit(client_id=client_id,client_secret=client_secret,password=password,user_agent=user_agent,username=username) + log_info("Logged in reddit as " + str(self.reddit.user.me())) self.items_cache=dict() self.stop = False @@ -107,18 +118,23 @@ class RedditNetwork(Network): return if not hasattr(item.author,'name'): log_warn('author of %s has no name field, ignored' % str(item.id)) - try: - item.mark_as_read() - except Exception,e: - log_warning('Failed to mark %s as read: %s' % (item.id,str(e))) + if True: + try: + item.mark_read() + except Exception,e: + log_warn('Failed to mark %s as read: %s' % (item.id,str(e))) return author=self.canonicalize(item.author.name) - if author==self.canonicalize(self.login): + if author and author==self.canonicalize(self.login): return if item.id in self.last_seen_ids: - #log_log('Already seen %s %.1f hours ago by %s: %s (%s), skipping' % (item.id,age/3600,str(author),repr(title),repr(item.body))) + log_log('Already seen %s %.1f hours ago by %s: %s (%s), skipping' % (item.id,age/3600,str(author),repr(title),repr(item.body))) + try: + item.mark_read() + except Exception,e: + log_warn('Failed to mark %s as read: %s' % (item.id,str(e))) return age=time.time()-item.created_utc @@ -155,7 +171,7 @@ class RedditNetwork(Network): line=line.replace(self.keyword,'').strip() if self.on_command: try: - parent_item=self.reddit.get_info(thing_id=item.parent_id) + parent_item=next(self.reddit.info([item.parent_id])) if not hasattr(parent_item,'author'): raise RuntimeError('Parent item has no author') author=parent_item.author.name @@ -167,10 +183,11 @@ class RedditNetwork(Network): self.on_command(link,synthetic_cmd) except Exception,e: log_error('Failed to tip %s\'s parent: %s' % (item.id,str(e))) - try: - item.mark_as_read() - except Exception,e: - log_warning('Failed to mark %s as read: %s' % (item.id,str(e))) + if True: + try: + item.mark_read() + except Exception,e: + log_warn('Failed to mark %s as read: %s' % (item.id,str(e))) def _schedule_reply(self,item,recipient,text): log_log('scheduling reply to %s:%s: %s' % (item.id if item else '""',recipient or '""',text)) @@ -214,7 +231,10 @@ class RedditNetwork(Network): if fullname in self.items_cache: item=self.items_cache[fullname] if not item: - item=self.reddit.get_info(thing_id=fullname) + item = self.reddit.mesage(fullname) + if not item: + gen=self.reddit.info([fullname]) + item=next(gen, None) if not item: log_error('Failed to find item %s to post %s' % (fullname,text)) redis_lpop('reddit:replies') @@ -226,9 +246,6 @@ class RedditNetwork(Network): redis_lpop('reddit:replies') - except praw.errors.RateLimitExceeded,e: - log_info('Rate limited trying to send %s, will retry: %s' % (data,str(e))) - return False except Exception,e: log_error('Error sending %s, will retry: %s' % (data,str(e))) return False @@ -256,15 +273,15 @@ class RedditNetwork(Network): self._parse(message,not message.was_comment) else: - messages=self.reddit.get_inbox() - for message in messages: - if not message.was_comment: + for message in self.reddit.inbox.unread(limit=self.load_limit): + #if not message.was_comment: self._parse(message,True) - sr=self.reddit.get_subreddit("+".join(self.subreddits)) - comments=sr.get_comments(limit=self.load_limit) - for comment in comments: - self._parse(comment,False) + #print "Submissions from %s" % ("+".join(self.subreddits)) + #sr=self.reddit.subreddit("+".join(self.subreddits)) + #for s in sr.new(limit=self.load_limit): + # for comment in s.comments: + # self._parse(comment,False) while self._post_next_reply(): pass