示例#1
0
 def create_kik_bot(self):
     self._kik_bot = KikApi(
         self.configuration.client_configuration.bot_name,
         self._bot_api_key)
     self._kik_bot.set_configuration(
         Configuration(
             webhook=self.configuration.client_configuration.webhook))
示例#2
0
    def setUp(self):
        super(KikBotApiTest, self).setUp()

        self.requests_mock = mock.patch('requests.api.request',
                                        wraps=requests_raise_func)
        self.requests_mock.start()

        self.api = KikApi('mybotusername', 'mybotapikey')
示例#3
0
def setup():
    """Sets up the bot."""
    with open('data.json') as d:
        config = json.load(d)
    print(config)
    app = Flask(__name__)
    kik = KikApi(config["bot_name"], config["api_key"])
    kik.set_configuration(Configuration(webhook=config["hostname"]))
    blobber = Blobber(analyzer=NaiveBayesAnalyzer())  # , classifier = cl)
    raven_client = Client(config['sentry_hook'])
    return app, blobber, config, kik
示例#4
0
    def create_kik_bot(self):
        if self._bot_api_key is not None:
            kik_bot = KikApi(self.configuration.client_configuration.bot_name,
                             self._bot_api_key)
            kik_bot.set_configuration(
                Configuration(
                    webhook=self.configuration.client_configuration.webhook))
            return kik_bot

        else:
            YLogger.error(self,
                          "Kik bot api key missing, unable to create kik bot")
            return None
示例#5
0
def init():
    """ Main program """
    kik = KikApi(BOT_USERNAME, BOT_API_KEY)
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    logging.debug('setting webhook to %s', WEBHOOK)
    kik.set_configuration(Configuration(webhook=WEBHOOK))
    app = KikBot(kik, __name__)
    if PORT:
        app.run(port=PORT, host='127.0.0.1', debug=True)  # from command line
    else:
        return app
def init_app(path):
    """
    Ensure that the configuration file is loaded by the web server before it is given the Flask app.
    :param path: Location of the json configuration file for the application to be run.
    :return: The flask app object, to be used as the WSGI application.
    """
    global config, kik, queue, parser

    with open(path) as config_file:
        config = json.load(config_file)

    Database.init_database(config)

    kik = KikApi(config['bot_username'], config['bot_api_key'])
    kik.set_configuration(Configuration(webhook=config['webhook']))
    queue = MessageQueue(config, kik)
    parser = MessageParser(config, queue)

    return app
示例#7
0
 def __init__(self,
              username,
              api_key,
              webhook,
              case_sensitive=False,
              command_list="Commands"):
     self.functions = {}
     self.help = {}
     self.kik = KikApi(username, api_key)
     self.kik.set_configuration(Configuration(webhook=webhook))
     self.case_sensitive = case_sensitive
     if not isinstance(command_list, str):
         command_list = None
     if not case_sensitive:
         if command_list != None:
             command_list = command_list.lower()
     self.command_list_command = command_list
     self.keyboard_entries = [
         self.command_list_command
     ] if case_sensitive else [self.command_list_command.title()]
示例#8
0
        if profile_picture is not None:
            messages_to_send.append(
                # Another type of message is the PictureMessage - your bot can send a pic to the user!
                PictureMessage(to=message.from_user,
                               chat_id=message.chat_id,
                               pic_url=profile_picture))

            profile_picture_response = "Here's your profile picture!"
        else:
            profile_picture_response = "It does not look like you have a profile picture, you should set one"

        messages_to_send.append(
            TextMessage(to=message.from_user,
                        chat_id=message.chat_id,
                        body=profile_picture_response))

        return messages_to_send


if __name__ == "__main__":
    """ Main program """
    kik = KikApi('prodfriend', '958137de-1eac-4b5c-a440-5bc5c36d769a')
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    kik.set_configuration(
        Configuration(webhook='http://bdc639a1.ngrok.io/incoming'))
    app = KikBot(kik, __name__)
    app.run(port=8080, host='127.0.0.1', debug=True)
示例#9
0
from flask import Flask, request, Response
import os
from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage, PictureMessage, StartChattingMessage
from clarifai.client import ClarifaiApi 
KIK_USERNAME = os.environ['KIK_USERNAME'] 
KIK_API_KEY = os.environ['KIK_API_KEY'] 
WEBHOOK =  os.environ['WEBHOOK']
app = Flask(__name__)
kik = KikApi(KIK_USERNAME, KIK_API_KEY)
kik.set_configuration(Configuration(webhook=WEBHOOK))
clarifai_api = ClarifaiApi() 

words = [] 
counter = 0 

@app.route('/', methods=['POST'])
def incoming():
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()):
        return Response(status=403) 
   
    messages = messages_from_json(request.json['messages'])
    for message in messages:
        if isinstance(message, StartChattingMessage):
            kik.send_messages([
            TextMessage(
            to=message.from_user,
            chat_id = message.chat_id,
            body='Hello Im the Mad Lib Bot! Send me pictures and Ill tell a wacky random story based on the tags of the image. Ill take the first 5 pics :)'
            ),
            ])  
示例#10
0
            location = geolocator.geocode(street, language=lang)
        except:
            pass

    return location


def geoip():
    ip = request.headers.get('X-Forwarded-For', request.remote_addr)
    if ',' in ip:
        ip = ip.split(',')[0]
    return geo.get(ip)


if config.KIK_BOT_ENABLED:
    kik_service = KikApi(config.KIK_BOT_USERNAME, config.KIK_BOT_KEY)
    try:
        kik_service.set_configuration(
            Configuration(webhook='https://%s%s' %
                          (config.SERVER_NAME, config.KIK_BOT_WEBHOOK)))
    except Exception as e:
        logging.warning(e)
else:
    kik_service = None

if config.MICROSOFT_BOT_ENABLED:
    microsoft_service = BotFrameworkMicrosoft(config.MICROSOFT_BOT_ID,
                                              config.MICROSOFT_BOT_KEY)
else:
    microsoft_service = None
示例#11
0
        self.response_messages.append(
            TextMessage(to=self.message.from_user,
                        chat_id=self.message.chat_id,
                        body=message))

    def send_message_with_responses(self, message, responses):
        text_responses = []

        for response in responses:
            text_responses.append(TextResponse(response))

        self.response_messages.append(
            TextMessage(to=self.message.from_user,
                        chat_id=self.message.chat_id,
                        body=message,
                        keyboards=[
                            SuggestedResponseKeyboard(responses=text_responses)
                        ]))


if __name__ == "__main__":
    """ Main program """
    kik = KikApi('studyhelper', 'be6f061d-69f2-401a-9fad-0a31aa9cac68')
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    kik.set_configuration(Configuration(webhook=LISTENING_SERVER +
                                        '/incoming'))
    app = KikBot(kik, __name__)
    app.run(port=8080, host='127.0.0.1', debug=True)
示例#12
0
import sys
import mysql.connector
from datetime import date


class mymenu:
    def __init__(self, date, menu, menu_id):
        self.date = date
        self.menu = menu
        self.menu_id = menu_id


my_date = date.today()

app = Flask(__name__)
kik = KikApi("chinyeebot", "8ed8ec43-b3c6-45d9-85e4-0e4442d592a4")
mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net",
                               user="******",
                               passwd="2c2f1c38",
                               database="heroku_5a951cfac26923b")
mycursor = mydb.cursor()
#sql = "select menu from menu join lunch_info on lunch_info.menu_id=menu.id where date=?"

mycursor.execute(
    "select * from menu join lunch_info on lunch_info.menu_id = menu.id where date = %(date)s",
    {'date': my_date})

a = mycursor.fetchall()[0]
my_menu = a[1]
my_menu_id = a[0]
today = mymenu(my_date, my_menu, my_menu_id)
示例#13
0
from flask import Flask, request, Response
from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage

botName = "hautebot"
botApiKey = "e4249cf1-4ced-4877-944d-b5ee05e3bf63"

app = Flask(__name__)
app.config['DEBUG'] = True
kik = KikApi(botName, botApiKey)


@app.route('/', methods=['POST'])
def handleRequest():
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'),
                                request.get_data()):
        return Response(status=403)

    messages = messages_from_json(request.json['messages'])

    for message in messages:
        if isinstance(message, TextMessage):
            kik.send_messages([
                TextMessage(to=message.from_user,
                            chat_id=message.chat_id,
                            body=message.body)
            ])

        return Response(status=200)

示例#14
0
        profile_picture = user.profile_pic_url

        if profile_picture is not None:
            messages_to_send.append(
                # Another type of message is the PictureMessage - your bot can send a pic to the user!
                PictureMessage(
                    to=message.from_user,
                    chat_id=message.chat_id,
                    pic_url=profile_picture
                ))

            profile_picture_response = "Here's your profile picture!"
        else:
            profile_picture_response = "It does not look like you have a profile picture, you should set one"

        messages_to_send.append(
            TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response))

        return messages_to_send


if __name__ == "__main__":
    """ Main program """
    kik = KikApi('skb1992_007', 'dffc79c9-ad98-44a3-bda5-ba98ce90f4b9')
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    kik.set_configuration(Configuration(webhook='https://a3a2fe23.ngrok.io/incoming'))
    app = KikBot(kik, __name__)
    app.run(port=8080, host='127.0.0.1', debug=True)
示例#15
0
def kik_setup_python(webhook):
    BOT_USERNAME = '******'
    BOT_API_KEY = 'e9dbcaf7-5d17-4ab7-b078-5fbd8a5a244d'
    kik = KikApi(BOT_USERNAME, BOT_API_KEY)
    config = Configuration(webhook=webhook)
    kik.set_configuration(config)
示例#16
0
        if profile_picture is not None:
            messages_to_send.append(
                # Another type of message is the PictureMessage - your bot can send a pic to the user!
                PictureMessage(
                    to=message.from_user,
                    chat_id=message.chat_id,
                    pic_url=profile_picture
                ))

            profile_picture_response = "Here's your profile picture!"
        else:
            profile_picture_response = "It does not look like you have a profile picture, you should set one"

        messages_to_send.append(
            TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response))

        return messages_to_send


if __name__ == "__main__":
    """ Main program """
    kik = KikApi('bear.bot1', 'a7343fdc-e454-4b05-83d2-70fc8bb531f7')
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    kik.set_configuration(Configuration(webhook='https://38cc2287.ngrok.io/'))
    app = KikBot(kik, __name__)
    app.run(port=9999, host='localhost', debug=True)
    #app.run(port=4040, host='127.0.0.1')
示例#17
0
        profile_picture = user.profile_pic_url

        if profile_picture is not None:
            messages_to_send.append(
                # Another type of message is the PictureMessage - your bot can send a pic to the user!
                PictureMessage(to=message.from_user,
                               chat_id=message.chat_id,
                               pic_url=profile_picture))

            profile_picture_response = "Here's your profile picture!"
        else:
            profile_picture_response = "It does not look like you have a profile picture, you should set one"

        messages_to_send.append(
            TextMessage(to=message.from_user,
                        chat_id=message.chat_id,
                        body=profile_picture_response))

        return messages_to_send


if __name__ == "__main__":
    """ Main program """
    kik = KikApi('BOT_USERNAME_HERE', 'BOT_API_KEY_HERE')
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    kik.set_configuration(Configuration(webhook='WEBHOOK_HERE'))
    app = KikBot(kik, __name__)
    app.run(port=8080, host='127.0.0.1', debug=True)
示例#18
0
from flask import Flask, request, Response
import requests, json
from champion import *
from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage, StartChattingMessage, IsTypingMessage

app = Flask(__name__)
kik = KikApi("leaguestats", "d7fdd8fa-d642-4517-bda4-2392a5820db4")
api_key = "d7fdd8fa-d642-4517-bda4-2392a5820db4"
riotKey = 'RGAPI-33ddda68-2769-46cc-8a03-1c8c393551ad'

kik.set_configuration(Configuration("https://1556b3a4.ngrok.io/inc"))


@app.route('/inc', methods=['POST'])
def inc():
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'),
                                request.get_data()):
        return Response(status=403)

    #chatID = None
    chatMessage = None
    greetingMessage = "Welcome to LeagueStats! Type in your summoner name in order to find out your\
	worst 3 champions!"

    userNotExist = "This user doesn't exist, please try to enter another summoner name."

    messages = messages_from_json(request.json['messages'])

    for message in messages:
        if isinstance(message, StartChattingMessage):
示例#19
0
from flask import Flask, request, Response

from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage

app = Flask(__name__)
kik = KikApi("female_lama", "42cd379e-5f1a-4390-881d-955f028221e2")

kik.set_configuration(
    Configuration(webhook="https://22e81a38.ngrok.io/incoming"))

live_dict = {}


def user_is_admin(username):
    return username in [
        "ilike3pancakes", "oskarsbanana", "YG_Bands_", "vikiid95", "goditee",
        "BossJordan_g", "Its_Margo_", "yoitscass28"
    ]


def maybe_do_verify(_text_message):
    if not user_is_admin(_text_message.from_user):
        return _text_message.body

    user = _text_message.body.split("verify with me ")
    if len(user) < 2 or len(user[1]) < 1:
        return "Please verify with the admin @%s" % _text_message.from_user

    return "Hello %s, the group admin @%s is asking for verification. Please send a live photo to them using the kik camera to prove that your kik profile is real." % (
        user[1], _text_message.from_user)
示例#20
0
        profile_picture = user.profile_pic_url

        if profile_picture is not None:
            messages_to_send.append(
                # Another type of message is the PictureMessage - your bot can send a pic to the user!
                PictureMessage(
                    to=message.from_user,
                    chat_id=message.chat_id,
                    pic_url=profile_picture
                ))

            profile_picture_response = "ini dia foto kamuu!"
        else:
            profile_picture_response = "ga mirip loh, yaudh lah yaa"

        messages_to_send.append(
            TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response))

        return messages_to_send


if __name__ == "__main__":
    """ Main program """
    kik = KikApi('dodebot', '50c8dd0b-3eee-4b6d-a75e-22d1ea3abecf')
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    kik.set_configuration(Configuration(webhook='https://a62f7c5e.ngrok.io/incoming'))
    app = KikBot(kik, __name__)
    app.run(port=8080, host='127.0.0.1', debug=True)
示例#21
0
 def __init__(self, username, api_key):
     self.engine = Engine()
     self.username = username
     self.api_key = api_key
     self.kik = KikApi(username, api_key)
示例#22
0
from flask import Flask, request, Response
from kik import KikApi, Configuration, KikError
from kik.messages import messages_from_json, TextMessage
from kik_hangman_session import Hangman
import json
import logging
from kik_sql import KikDB
import os

logging.basicConfig(filename='hangmanlog.log',
                    level=logging.INFO,
                    format="[%(asctime)s] %(message)s")

app = Flask(__name__)
kik = KikApi('gameofhangman', os.environ['KIK_API_KEY'])
Hangman.kik = kik
code = kik.create_code(
    {os.environ['KIK_CODE_KEY']: os.environ['KIK_CODE_VALUE']})
server_url = 'http://' + os.environ['KIK_HOSTNAME'] + ':8080/incoming'
kik.set_configuration(Configuration(webhook=server_url))


def logprint(msg, *args):
    logging.info(msg)
    for i in args:
        logging.info(str(i))
    print(msg, args)


@app.route('/incoming', methods=['POST'])
示例#23
0
from flask import Flask, request, Response

from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage

try:
    from settings import *
except ImportError:
    from settings.example import *

app = Flask(__name__)
kik = KikApi(BOT_USERNAME, BOT_API_KEY)

kik.set_configuration(Configuration(webhook=WEBHOOK))

@app.route('/webhook', methods=['POST'])
def incoming():
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()):
        return Response(status=403)

    messages = messages_from_json(request.json['messages'])

    for message in messages:
        if isinstance(message, TextMessage):
            kik.send_messages([
                TextMessage(
                    to=message.from_user,
                    chat_id=message.chat_id,
                    body=message.body
                )
            ])
示例#24
0
        if profile_picture is not None:
            messages_to_send.append(
                # Another type of message is the PictureMessage - your bot can send a pic to the user!
                PictureMessage(to=message.from_user,
                               chat_id=message.chat_id,
                               pic_url=profile_picture))

            profile_picture_response = "ini dia foto kamuu!"
        else:
            profile_picture_response = "ga mirip loh, yaudh lah yaa"

        messages_to_send.append(
            TextMessage(to=message.from_user,
                        chat_id=message.chat_id,
                        body=profile_picture_response))

        return messages_to_send


if __name__ == "__main__":
    """ Main program """
    kik = KikApi('botmca', 'fffa79e9-afe9-45e4-b2bd-6ec78732b3de')
    # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
    # or if the configuration changes. In a production setting, you would only issue this call if you need to change
    # the configuration, and not every time the bot starts.
    kik.set_configuration(
        Configuration(webhook='https://7c50a1a4.ngrok.io/incoming'))
    app = KikBot(kik, __name__)
    app.run(port=8080, host='127.0.0.1', debug=True)
示例#25
0
 def init_bot(self):
     self._bot = KikApi(self.username, self.api_key)
示例#26
0
from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage
#from tag_speech import SpeechTagger
# import responses
from responses import UsrgreetingList, messageList, help_str
from weather_request import *
from wit import Wit

bot = Wit(access_token="VOCFYQI6MHUL7CDRMPURE4Z26KJGNL7G")

usr_name = 'glooffybot'
key = '71981fb3-c57d-43bf-ac84-534120e8857e'
weather_key = "396cbf110cc7bd1bd3087f317643a83f"

app = Flask(__name__)
kik = KikApi(usr_name, key)

# this is for the kik server. It sets up the webhook so that kik server can
# send messages to the webhook and then incoming function extracts the data
# recieved.
kik.set_configuration(Configuration(webhook='https://glooffy.herokuapp.com/'))


def SendMessage(user, ch_id, msg):
    # sends a single message
    kik.send_messages([TextMessage(to=user, chat_id=ch_id, body=msg)])


@app.route('/', methods=['POST'])
def incoming():
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'),
示例#27
0
文件: app.py 项目: tsharma2/kik-bot
from flask import Flask, request, Response

from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage, VideoMessage

##### NEW #####
from config import username, api_key, webhook

##### NEW #####
from giphypop import translate

app = Flask(__name__)
kik = KikApi(username, api_key)
kik.set_configuration(Configuration(webhook=webhook))


######
def giffy(message):
    img = translate(message, api_key='dc6zaTOxFJmzC')
    gif = img.fixed_height.url
    print(gif)
    return gif


#######


@app.route('/incoming', methods=['POST'])
def incoming():
    print('coming in here')
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'),
示例#28
0
        print(
            "[{bot_username}] Could not load custom module: custom_modules.{custom_module} ... - ignoring"
            .format(custom_module=custom_module_name,
                    bot_username=bot_username))

# prepare database
if custom_module is not None and hasattr(custom_module,
                                         "ModuleCharacterPersistentClass"):
    db_class = custom_module.ModuleCharacterPersistentClass(
        default_config, bot_username)
else:
    db_class = CharacterPersistentClass(default_config, bot_username)
del db_class

kik_api = KikApi(
    bot_username,
    default_config.get("BotAuthCode", "abcdef01-2345-6789-abcd-ef0123456789"))
LazyKikUser.kik_api = kik_api
# For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once
# or if the configuration changes. In a production setting, you would only issue this call if you need to change
# the configuration, and not every time the bot starts.
kik_api.set_configuration(
    Configuration(webhook="{}:{}/incoming".format(
        default_config.get("RemoteHostIP", "www.example.com"),
        default_config.get("RemotePort", "8080"))))

print("[{bot_username}] Debug URL: {host}:{port}/debug".format(
    bot_username=bot_username,
    host=default_config.get("RemoteHostIP", "www.example.com"),
    port=default_config.get("RemotePort", "8080")))
print("[{bot_username}] Started: {now:%d.%m.%Y %H:%M:%S}".format(
示例#29
0
from MessageBuilder import MessageBuilder
from flask import Flask, request, Response
from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage, ReceiptMessage, ReadReceiptMessage, SuggestedResponseKeyboard, TextResponse, StartChattingMessage
import os
reset = False
resetUser = ""
MessageHandler = MessageBuilder()
app = Flask(__name__)
kik = KikApi('BOTID', 'API_KEY')

#-------------------------KIK BOT CONFIG------------------------------------------------------

afeatures = {
    "manuallySendReadReceipts": False,
    "receiveReadReceipts": True,
    "receiveDeliveryReceipts": False,
    "receiveIsTyping": False
}

staticKeyboard = SuggestedResponseKeyboard(responses=[
    TextResponse('BENCHMARK ANALYSIS'),
    TextResponse('PROBE ANALYSIS'),
    TextResponse('INACTIVE ANALYSIS'),
    TextResponse('HELP')
])

kik.set_configuration(
    Configuration(webhook='WEBHOOK',
                  features=afeatures,
                  static_keyboard=staticKeyboard))
示例#30
0
 def __init__(self, BOT_USER_NAME, API_KEY):
     global kik
     kik = KikApi(BOT_USER_NAME, API_KEY)