示例#1
0
#Import class from the other file
from bot import telegram_chatbot
from datetime import datetime
from budgettracker import BudgetTracker
from robinhood import Robinhood

update_id = None

#Instantiate objects - telegram_chatbot and BudgetTracker
bot = telegram_chatbot('config.cfg')
tracker = BudgetTracker()
robinhood = Robinhood()


def make_reply(msg):
    try:
        if msg is not None:
            #Splits message into list of items
            output = msg.split(', ')

            #Get the command (1st item in the comma-separated list)
            command = output[0]

            #Get the arguments (if any) (subsequent items in the comma-separated list)
            if len(output) > 1:
                args = output[1:]
            else:
                args = None

            #Returns help text
            if command == 'Help':
示例#2
0
from bot import telegram_chatbot
import gizoogle

bot = telegram_chatbot("config.cfg")

update_id = None


def make_reply(msg):
    reply = None
    if msg is not None:
        reply = gizoogle.text(msg)
    return reply


while True:
    updates = bot.get_updates(offset=update_id)
    print(updates)
    updates = updates.get("result", None)
    if updates:
        for item in updates:
            update_id = item["update_id"]
            try:
                message = item["message"]["text"]
            except:
                message = None
            from_ = item["message"]["from"]["id"]
            reply = make_reply(message)
            bot.send_message(reply, from_)
示例#3
0
from bot import telegram_chatbot
import threading
import dateutil.parser
import datetime as dt
import time

bot = telegram_chatbot()
lock = threading.Lock()


def make_reply(msg, sender):
    reply = None
    if msg is not None:
        if msg == "/help":
            return "Hello! I will remind you to take your birth control on a daily basis.\n\n" \
                "You can use the following commands to control me:\n" \
                "💊 /start - To start the pill reminders.\n" \
                "⏰ /settime - If you set a wrong time, you can re-set it with this command.\n" \
                "🛑 /stop - Stop getting reminders and delete your cycle.\n" \
                "❓ /help - This help message you're seeing right now."
        if bot.status.get(sender, "") == "set_time":
            lock.acquire()
            try:
                try:
                    time = dateutil.parser.parse(msg, dayfirst=True)
                    bot.time[sender] = time
                    bot.reminder[sender] = time.replace(
                        day=dt.datetime.utcnow().day)
                    bot.status[sender] = "running"
                    add_reminder(sender, msg)
                    print("Set time for {}. Start: {}, Reminder: {}".format(
示例#4
0
import datetime
import sys

'''
GPIO cleanup at start in case the program crashed or was shutdown by cutting power
Setting GPIO warnings to false, because we have no need for the warnings at this time
'''
GPIO.setwarnings(False)
GPIO.cleanup()

'''
Bot setup
'''
update_id = None
config = "config.ini"
bot = telegram_chatbot(config)

'''
Parser setup
'''
parser = configparser.SafeConfigParser()

'''
Scale setup
'''
scale = Scale(5, 6, 1509)

'''
cleanAndExit. Cleans the GPIO and exists in case of a
KeyboardInterrupt
'''
 def __init__(self):
     self.bot = telegram_chatbot(".config.cfg")
     self.alpaca = alpaca_bot(".config.cfg")
示例#6
0
from bot import telegram_chatbot
import random

update_id = None

bot = telegram_chatbot("botConfig.cfg")

def generate_insult(name):
    insult_number = random.randint(0, 2)
    if insult_number == 0:
        return name + " you room temperature iq snail"
    elif insult_number == 1:
        return "Hey " + name + ", You know what the difference between your momma and a washing machine is? When I dump a load in a machine, the machine doesn't follow me around for three weeks."
    elif insult_number == 2:
        return name + " single from the womb, single till the tomb"

def make_reply(message):
    if message is not None:
        if message.startswith("/insult"):
            split_text = message.split()
            if len(split_text) != 2:
                return "invalid command"
            return generate_insult(split_text[1])
        return "invalid command"
    return None

while True:
    updates = bot.get_updates(offset = update_id)
    updates = updates["result"]
    if updates:
        for item in updates:
示例#7
0
from bot import telegram_chatbot
import daVinci
bot = telegram_chatbot("E:/daVinci/config.cfg")

update_id = None
print('The Server is running')
while True:
    updates = bot.get_updates(offset=update_id)
    updates = updates["result"]
    if updates:
        for item in updates:
            update_id = item["update_id"]
            try:
                message = str(item["message"]["text"])
            except:
                message = None
            from_ = item["message"]["from"]["id"]
            reply, mode = daVinci.make_reply(message)
            if reply is None:
                bot.send_message('Something went wrong', from_)
            else:
                if mode == 0:
                    bot.send_message(reply, from_)
                elif mode == 1:
                    bot.send_markdown(reply, from_)
                elif mode == 2:
                    bot.send_image(reply, from_)
                elif mode == 3:
                    bot.send_image(reply[1], from_)
                    bot.send_message(reply[0], from_)
                elif mode == 4: