Skip to content
Permalink
Browse files

Some statistics

  • Loading branch information
YogurtTheHorse committed Sep 23, 2016
1 parent b8e9c41 commit 36ab81a5c1a5462939430fa952746e0ba126bbbf
Showing with 68 additions and 0 deletions.
  1. +47 −0 botan.py
  2. +9 −0 main.py
  3. +12 −0 statistics.py
@@ -0,0 +1,47 @@
# ----------------
# dont forget 'pip install requests' first
# ----------------
# usage example:
#
# import botan
#
# print botan.track(1111, 1, {'text':2}, 'Search')

import requests
import json


TRACK_URL = 'https://api.botan.io/track'
SHORTENER_URL = 'https://api.botan.io/s/'


def track(token, uid, message, name='Message'):
try:
r = requests.post(
TRACK_URL,
params={"token": token, "uid": uid, "name": name},
data=json.dumps(message),
headers={'Content-type': 'application/json'},
)
return r.json()
except requests.exceptions.Timeout:
# set up for a retry, or continue in a retry loop
return False
except (requests.exceptions.RequestException, ValueError) as e:
# catastrophic error
print(e)
return False


def shorten_url(url, botan_token, user_id):
"""
Shorten URL for specified user of a bot
"""
try:
return requests.get(SHORTENER_URL, params={
'token': botan_token,
'url': url,
'user_ids': str(user_id),
}).text
except:
return url
@@ -2,6 +2,8 @@

import config

import statistics

from telegram.ext.dispatcher import run_async
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram.ext import Job
@@ -90,6 +92,8 @@ def start(bot, update):
image = None
buttons = None

statistics.track(c_id, update.message.text, 'Start')

def rep(txt, btns=None, photo=None):
global msg, image, buttons

@@ -119,8 +123,11 @@ def rep(txt, btns=None, photo=None):
reply(c_id, bot, msg, buttons, image)

def setname(bot, update):

txt = update.message.text
if len(txt) > len('/setname'):
statistics.track(update.message.chat_id, update.message.text, 'Setname')

name = txt[len('/setname')+1:]
usermanager.setname(update.message.chat_id, name)

@@ -294,6 +301,7 @@ def rep(txt, btns=None, photo=None):

def msg(bot, update):
c_id = update.message.chat_id
statistics.track(c_id, update.message.text)

global msg, image, buttons
msg = ''
@@ -370,6 +378,7 @@ def leaderboard(bot, update):
bot.sendMessage(update.message.chat_id, text=msg)

def stop(bot, update):
statistics.track(update.message.chat_id, update.message.text, 'Stop')
usermanager.delete(update.message.chat_id)

def cesar(bot, update):
@@ -0,0 +1,12 @@
import botan
import config

tkn = None

if hasattr(config, 'BOTANIO_TOKEN'):
tkn = config.BOTANIO_TOKEN

def track(uid, message, name='Message'):
if tkn is not None:
botan.track(tkn, uid, message, name)

0 comments on commit 36ab81a

Please sign in to comment.
You can’t perform that action at this time.