COMMUNITY
Python Code
Is it possible to implement this code to my bot?
# coding: utf-8
#!/usr/bin/env python
#
# Based on https://pastebin.com/VU2v27bH
# Author: Kirill Vasin
import logging
from time import time
from collections import deque
logger = logging.getLogger(__name__)
class SpamFilter:
def __init__(self):
self.limits = {1:3, 5:7, 10:10} # max: 3 updates in 1 second, 7 updates in 5 seconds, 10 updates in 10 seconds
self.timeout_start = 10
self.severity = 2
self.timeouts = {}
self.times = {}
self.violations = {}
def new_message(self, chat_id):
update_time = time()
if chat_id not in self.timeouts:
self.timeouts.update({chat_id: 0})
self.times.update({chat_id : deque(maxlen=10)})
self.violations.update({chat_id: 0})
else:
if self.timeouts[chat_id] > update_time:
return 1
for limit in self.limits:
amount = 1
for upd_time in self.times[chat_id]:
if update_time - upd_time < limit:
amount += 1
else:
break
if amount > self.limits[limit]:
delta = int(self.timeout_start * self.severity ** self.violations[chat_id])
self.timeouts[chat_id] = update_time + delta
self.violations[chat_id] += 1
logger.warning("User %s is sending too many requests, broke %s limit", chat_id, limit)
return "Too many requests. Operations will be availiable in {0}".format(delta)
self.times[chat_id].appendleft(update_time)
return False
def wrapper(self, func): # only works on functions, not on instancemethods
# Only works for messages (+Commands) and callback_queries (Inline Buttons)
def func_wrapper(bot, update):
if update.callback_query:
chat_id = update.callback_query.from_user.id
elif update.message:
chat_id = update.message.chat_id
timeout = self.new_message(chat_id)
if not timeout:
return func(bot, update) # return is required by ConversationHandler
elif timeout != 1:
bot.sendMessage(chat_id=chat_id, text=timeout)
return func_wrapper
blocker = SpamFilter()
# @blocker.wrapper
# def start(bot, update):
#
Thank you
Posted by Wolfy over 4 years ago
Custom Variable Bug
Hy,
I have a question with custom variables.
I would like to make a logical statement, but you make it really hard. Because you only let the result of the logical statement to be a text...
Additionally what kind of IF statement this is if there is a False result..? For example fallback could be used as a False statement.
What I wanted to do is to decide whether an extracted data is true or false and use the result.
For example using it for a custom variable:
Bot statement 1: Give a value. [customVar mark=1]
User: 2
Bot statement 2: Are you sure? [customVar mark=[IF([extractedData interaction=1 fallback=1]=2){10}]]
User: Yes
Bot statement 3: Your value: [showVar=mark]
In this case it the custom variable mark will be 10.
But there is a bug:
extractedData interaction=1 is not "2" the Bot statement 2 will write [customVar mark=]
Even though the result at Bot statement 3 is good, cause variable value will be 1.
So can you do something with the unwanted [customVar mark=] if the logical statement is fale?
Posted by Kristian Komjati over 5 years ago
Secure message like: password '****'
Hello! I have done a little research, but I can not find a way to resolve this situation:
I want the bot to ask the user a user name and a password for a certain purpose. How can the password be set to not be visible in chat? like '****' or 'XXXX'?
Thank you in advance
Posted by Andreea Grigoras about 4 years ago
buttons
How to include only buttons in snatchbot. Is their any option to be enabled.
one more question is how to increase number of buttons to be included in text card from 3 to more
Posted by Tulasi Snigdha over 5 years ago
REPORT
Bonjour, Je n'arrive pas à report mes réponses de bot sur un fichier excel
Merci de m'indiquer la procédure
Posted by Apetahi over 6 years ago
Get an element using javascript through the API?
How do I get an element by the class name, within the iframe, using the API?
Posted by Jack over 4 years ago
Cards not working
Hello.
I tried to show my bot and remarked that it was a mess. For example cards do not work. Check for examle bot 64229, interaction Z (1012521).
Thank you for your time
Posted by Christopher Lazaris over 4 years ago
Bug
HI, when i m test my interaction "name" all is ok but when im test all the chatbot, there is a bug, the bot send me the reponse of the number of person ! thanks in advance, it s very urgently
Posted by Anthony Mabille almost 5 years ago
Answers with more than 20 characters
Either quick answers or answers in text cards can only be 20 characters long. I need more space for longer answers! How can I do that?
Posted by Bruno Zimmerli over 5 years ago
programming language
Witch is the programming language used to develop Snatchbot?
Posted by Alma C over 2 years ago