Commit 7e8a7616 authored by Zeitpunk's avatar Zeitpunk 💬

[B] Added the missing 'self' arguments

parent b0cee52b
......@@ -7,6 +7,7 @@
import requests
import json
import urllib
class telefly:
......@@ -22,22 +23,22 @@ class telefly:
""" parses the JSON response (content) into a Python dictionary """
def getJson(url):
content = getUrl(url)
def getJson(self, url):
content = self.getUrl(url)
js = json.loads(content)
return js
""" retrieves a list of "updates" (aka. Messages to our bot) """
def getUpdates(offset=None): # offset is the last update id
def getUpdates(self, offset=None): # offset is the last update id
url = self.URL + "getUpdates?timeout=100" # using Long Polling to prevent high requests
if offset:
url += "&offset={}".format(offset) # with the offset parameter the api sends only the newer updates
js = getJson(url)
js = self.getJson(url)
return js
""" calculates the highest ID of all the updates """
def getLastUpdateId(updates):
def getLastUpdateId(self, updates):
update_ids = []
for update in updates["result"]:
update_ids.append(int(update["update_id"]))
......@@ -53,30 +54,30 @@ class telefly:
'find_location' for location data,
'record_video_note' or 'upload_video_note' for video notes.
"""
def sendAction(chat_id, action):
def sendAction(self, chat_id, action):
url = self.URL + "sendChatAction?action={}&chat_id={}".format(action, chat_id)
getUrl(url)
self.getUrl(url)
""" sends text to chat_id """
def sendMessage(text, chat_id, disable_notification=None, reply_markup=None):
def sendMessage(self, text, chat_id, disable_notification=None, reply_markup=None):
text = urllib.parse.quote_plus(text) # encode any special characters in our message to be url-friendly, for example the + sign
url = self.URL + "sendMessage?text={}&chat_id={}&parse_mode=Markdown".format(text, chat_id)
if disable_notification:
url += "&disable_notification={}".format(disable_notification)
if reply_markup:
url += "&reply_markup={}".format(reply_markup)
getUrl(url)
self.getUrl(url)
""" creates a keyboard to give it sendMessage """
def buildKeyboard(items):
def buildKeyboard(self, items):
keyboard = [[item] for item in items]
reply_markup = {"keyboard":keyboard, "one_time_keyboard": True}
return json.dumps(reply_markup)
""" not implemented yet
def sendPicture(chat_id):
def sendPicture(self, chat_id):
url = API + "sendPhoto?chat_id={}".format(chat_id)
filename = getPicture()
files = {'photo': open(filename, 'rb')}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment