Exemple #1
0
 def __init__(self):
     self.client = zulip.Client(site="https://chunkzz.zulipchat.com/api/")
     self.subscribe_all()
     self.chatbot = ChatBot(
         "Omega", trainer='chatterbot.trainers.ChatterBotCorpusTrainer')
     self.chatbot.train("chatterbot.corpus.english")
     self.crypto = Crypto()
     self.trans = Translate()
     self.g = Giphy()
     self.w = WikiPedia()
     self.tw = Twimega()
     self.motivate = Motivate()
     self.shortenedurl = Urlshortener()
     self.hacknews = Hackernews()
     self.geo = Geocode()
     self.weather = Weather()
     self.dict_ = Dictionary()
     self.joke = Joke()
     self.pnr = Pnr()
     self.mustread = Mustread()
     self.ss = Ss()
     self.cricket = Cricket()
     self.poll = Poll()
     self.subkeys = [
         "crypto", "translate", "define", "joke", "weather", "giphy", "pnr",
         "mustread", "poll", "hackernews", "hn", "HN", "motivate",
         "twitter", "screenshot", "memo", "cricnews", "help", "shorturl"
     ]
Exemple #2
0
 def __init__(self):
     self.client = zulip.Client(site="https://fazeup.zulipchat.com/api/")
     self.subscribe_all()
     self.hacknews = Hackernews()
     self.trans = Translate()
     self.movie = Movie()
     self.lyrics = Lyrics()
     self.holiday = Holiday()
     self.currency = Currency()
     self.cricket = Cricket()
     # self.chatbot.train("chatterbot.corpus.english")
     self.crypto = Crypto()
     self.trans = Translate()
     self.g = Giphy()
     self.w = WikiPedia()
     # self.tw = Twimega()
     # self.motivate = Motivate()
     self.shortenedurl = Urlshortener()
     self.geo = Geocode()
     self.weather = Weather()
     self.dict_ = Dictionary()
     self.joke = Joke()
     self.pnr = Pnr()
     self.mustread = Mustread()
     self.ss = Ss()
     self.cricket = Cricket()
     self.poll = Poll()
     print("done init")
     self.subkeys = [
         "crypto", "translate", "define", "joke", "weather", "giphy", "pnr",
         "mustread", "poll", "hackernews", "hn", "HN", "motivate",
         "twitter", "screenshot", "memo", "cricnews", "help", "shorturl",
         "movie", "currency", "holiday", "lyrics"
     ]
Exemple #3
0
	def __init__(self):
		self.client = zulip.Client(site="https://technh.zulipchat.com/api/", api_key="vkEQgQYDPUgAGmXaTXdMPsMwlkkgMfM5", email="*****@*****.**")
		self.subscribe_all()
		self.hacknews = Hackernews()
		self.trans = Translate()
		self.movie= Movie()
		self.lyrics = Lyrics()
		self.holiday = Holiday()
		self.currency = Currency()
		self.cricket = Cricket()
		self.github = GitHub()
		self.chatbot = ChatBot(name="technehru")

		print("done init")
		self.subkeys = ["use", "help", "translate", "hackernews", "hn", "hotel", "HN", "cricnews", "cricketnews", "movie", "currency", "holiday", "lyrics", "github"]
Exemple #4
0
    def on_message(self, message):
        global game

        if args.verbose:
            print YELLOW + message + END

        json_msg = json.loads(message)
        if 'msg' in json_msg:
            if json_msg['msg'] == 'HIT':
                on_sniffer_data('"number": ' + str(json_msg['number']) +
                                ', "power": 1')
            elif json_msg['msg'] == 'READY':
                if game is None:
                    game = Cricket()
                self.refresh(game.screenShot())
Exemple #5
0
    def __init__(self):
        self.client = zulip.Client(site="https://myra.zulipchat.com/api/")
        self.subscribe_all()
        self.hacknews = Hackernews()
        self.trans = Translate()
        self.movie = Movie()
        self.lyrics = Lyrics()
        self.holiday = Holiday()
        self.currency = Currency()
        self.cricket = Cricket()

        print("done init")
        self.subkeys = [
            "translate", "hackernews", "hn", "hotel", "HN", "askme",
            "cricnews", "movie", "currency", "holiday", "lyrics"
        ]
 def test_bowler_completes_second_over(self):
     self.assertEqual(
         Cricket.set_bowler_completed_over_count(
             {
                 'name': 'Archer',
                 'overs': 1,
                 'maidens': 0,
                 'runs': 0,
                 'wickets': 0
             }, 1), {
                 'name': 'Archer',
                 'overs': 2,
                 'maidens': 0,
                 'runs': 0,
                 'wickets': 0
             })
 def test_2_runs_is_even(self):
     self.assertEqual(Cricket.is_even(2), True)
 def test_batsman_cross(self):
     self.assertEqual(Cricket.batsman_cross("Smith", "Jones"),
                      ("Jones", "Smith"))
 def test_second_delivery_of_over_completed(self):
     self.assertEqual(Cricket.latest_delivery_completed(1), 2)
Exemple #10
0
 def test_first_delivery_of_over_completed(self):
     self.assertEqual(Cricket.latest_delivery_completed(0), 1)
Exemple #11
0
 def test_sixth_ball_bowled(self):
     self.assertEqual(Cricket.end_of_over_check(6), True)
Exemple #12
0
 def test_second_ball_bowled(self):
     self.assertEqual(Cricket.end_of_over_check(2), False)
Exemple #13
0
 def test_zero_balls_bowled(self):
     self.assertEqual(Cricket.end_of_over_check(0), False)
Exemple #14
0
 def test_new_over(self):
     self.assertEqual(
         Cricket.new_over("Archer", "Baker", "Charles", "Draper"),
         ("Baker", "Archer", "Draper", "Charles"))
Exemple #15
0
 def test_bowlers_swap(self):
     self.assertEqual(Cricket.swap_bowler("Smith", "Jones"),
                      ("Jones", "Smith"))
Exemple #16
0
 def test_sixth_delivery_of_over_completed(self):
     self.assertEqual(Cricket.latest_delivery_completed(5), 6)
Exemple #17
0
class ZulipBot(object):
	def __init__(self):
		self.client = zulip.Client(site="https://technh.zulipchat.com/api/", api_key="vkEQgQYDPUgAGmXaTXdMPsMwlkkgMfM5", email="*****@*****.**")
		self.subscribe_all()
		self.hacknews = Hackernews()
		self.trans = Translate()
		self.movie= Movie()
		self.lyrics = Lyrics()
		self.holiday = Holiday()
		self.currency = Currency()
		self.cricket = Cricket()
		self.github = GitHub()
		self.chatbot = ChatBot(name="technehru")

		print("done init")
		self.subkeys = ["use", "help", "translate", "hackernews", "hn", "hotel", "HN", "cricnews", "cricketnews", "movie", "currency", "holiday", "lyrics", "github"]

	def subscribe_all(self):
		json = self.client.get_streams()["streams"]
		streams = [{"name": stream["name"]} for stream in json]
		self.client.add_subscriptions(streams)

	def process(self, msg):
		content = msg["content"].split()
		sender_email = msg["sender_email"]
		ttype = msg["type"]
		stream_name = msg['display_recipient']
		stream_topic = msg['subject']

		print(content)

		if sender_email == BOT_MAIL:
			return 

		print("Sucessfully heard.")

		if content[0].lower() == "technehru" or content[0] == "@**Technehru**":
			if content[1].lower() == "help" or content[1].lower() == "use":
				message = open("help.txt", "r")
				self.client.send_message({
					"type": "stream",
					"to": stream_name,
					"subject": stream_topic,
					"content": message.read()
					})

			if content[1].lower() == "translate":
				ip = content[2:]
				ip = " ".join(ip)
				message = self.trans.translate(ip)
				self.client.send_message({
					"type": "stream",
					"subject": msg["subject"],
					"to": msg["display_recipient"],
					"content": message
					})
			if content[1].lower() == "movie":
				ip = content[2:]
				ip = " +".join(ip)
				message = self.movie.about(ip)
				self.client.send_message({
					"type": "stream",
					"subject": msg["subject"],
					"to": msg["display_recipient"],
					"content": message
					})

			if content[1].lower() == "lyrics":
				author = content[2]
				title = content[3:]
				title = " ".join(title)
				message = self.lyrics.about(author, title)
				self.client.send_message({
					"type": "stream",
					"subject": msg["subject"],
					"to": msg["display_recipient"],
					"content": message
					})

			if content[1].lower() == 'holiday':
				quote_data = self.holiday.holiday()
				self.client.send_message({
					"type": "stream",
					"to": stream_name,
					"subject": stream_topic,
					"content": quote_data
					})

			if content[1].lower() == 'currency':
				x = content[2]
				y = content[3]

				quote_data = self.currency.currency(x,y)
				self.client.send_message({
					"type": "stream",
					"to": stream_name,
					"subject": stream_topic,
					"content": quote_data
					})

			if content[1].lower() == "cricnews" or content[1].lower() == "cricketnews":
				news = self.cricket.news()
				self.client.send_message({
					"type": "stream",
					"subject": msg["subject"],
					"to": msg["display_recipient"],
					"content": news  
					})

			if content[1].lower() == 'hackernews' or content[1].lower() == 'hn':
				news = self.hacknews.get_hackernews()
				self.client.send_message({
					"type": "stream",
					"to": stream_name,
					"subject": stream_topic,
					"content": news
					})

			if content[1].lower() == 'github':
				if content[2].lower() == 'reopen' and content[3].lower() == 'issue':
					repo = content[4]
					num = int(content[5])
					result = self.github.reopen_issue(repo, num)
					self.client.send_message({
						"type": "stream",
						"to": stream_name,
						"subject": stream_topic,
						"content": result  
						})

				if content[2].lower() == 'comment' and content[3].lower() == 'issue':
					repo = content[4]
					num = int(content[5])
					comment = content[6:]
					comment = " ".join(comment)
					result = self.github.comment_issue(repo, num, comment)
					self.client.send_message({
						"type": "stream",
						"to": stream_name,
						"subject": stream_topic,
						"content": result  
						})

				if content[2].lower() == 'close' and content[3].lower() == 'issue':
					repo = content[4]
					num = int(content[5])
					result = self.github.close_issue(repo, num)
					self.client.send_message({
						"type": "stream",
						"to": stream_name,
						"subject": stream_topic,
						"content": result  
						})

				if content[2].lower() == 'assign' and content[3].lower() == 'issue':
					repo = content[4]
					num = int(content[5])
					assignee = content[6]
					result = self.github.assign_issue(repo, num, assignee)
					self.client.send_message({
						"type": "stream",
						"to": stream_name,
						"subject": stream_topic,
						"content": result  
						})


			if content[1] not in self.subkeys:
				ip = content[1:]
				ip = " ".join(ip)
				message = self.chatbot.get_response(ip).text
				self.client.send_message({
					"type": "stream",
					"subject": msg["subject"],
					"to": msg["display_recipient"],
					"content": message
					})

		
		elif "technehru" in content and content[0].lower() != "technehru":
			self.client.send_message({
				"type": "stream",
				"subject": msg["subject"],
				"to": msg["display_recipient"],
				"content": "Hey there! :blush:"
				})
		else:
			return
Exemple #18
0
 def test_first_ball_in_over_count(self):
     self.assertEqual(
         Cricket.increment_balls_bowled_by_bowler(1, {'overs': 0}, 0),
         "0.1")
Exemple #19
0
class ZulipBot(object):
    def __init__(self):
        self.client = zulip.Client(site="https://chunkzz.zulipchat.com/api/")
        self.subscribe_all()
        self.chatbot = ChatBot(
            "Omega", trainer='chatterbot.trainers.ChatterBotCorpusTrainer')
        self.chatbot.train("chatterbot.corpus.english")
        self.crypto = Crypto()
        self.trans = Translate()
        self.g = Giphy()
        self.w = WikiPedia()
        self.tw = Twimega()
        self.motivate = Motivate()
        self.shortenedurl = Urlshortener()
        self.hacknews = Hackernews()
        self.geo = Geocode()
        self.weather = Weather()
        self.dict_ = Dictionary()
        self.joke = Joke()
        self.pnr = Pnr()
        self.mustread = Mustread()
        self.ss = Ss()
        self.cricket = Cricket()
        self.poll = Poll()
        self.subkeys = [
            "crypto", "translate", "define", "joke", "weather", "giphy", "pnr",
            "mustread", "poll", "hackernews", "hn", "HN", "motivate",
            "twitter", "screenshot", "memo", "cricnews", "help", "shorturl"
        ]

    def urls(self, link):
        urls = re.findall(
            'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
            link)
        return urls

    def subscribe_all(self):
        json = self.client.get_streams()["streams"]
        streams = [{"name": stream["name"]} for stream in json]
        self.client.add_subscriptions(streams)

    def help(self):
        message = "**Welcome to Omega Bot**\nOmega Bot has various subfields\nType `omega help <subfield>` to get help for specific subfield.\n"
        message += "\n**Subfields**\n"
        message += "`crypto` - Get Crypto Currency Prices\n"
        message += "`translate` - Translate Foreign Languages to English\n"
        message += "`define` - Get Word Meanings\n"
        message += "`joke` - Get Jokes\n"
        message += "`weather` - Get Weather Details\n"
        message += "`giphy` - Get GIFs from Giphy\n"
        message += "`pnr` - Get PNR Status\n"
        message += "`mustread` - Share Must Read Messages to Teammates\n"
        message += "`poll` - Create Amazing Polls in Zulip\n"
        message += "`hn` - Get Top Hacker News Results\n"
        message += "`motivate` - Get Motivational Quotes\n"
        message += "`twitter` - Tweet Directly from Zulip\n"
        message += "`screenshot` - Take Screenshot of Web Pages\n"
        message += "`memo` - Create Memos in Cloud\n"
        message += "`cricnews` - Get Cricket News\n"
        message += "`shorturl` - Create goo.gl short URLs\n"
        message += "\nIf you're bored Talk to Omega Bot, it will supercharge you"
        return message

    def help_sub(self, key):
        key = key.lower()
        message = "**Usage**\n"
        if key == "crypto":
            message += "`omega crypto <crypto-currency-code>` - To Get Price in USD\n"
            message += "`omage crypto <crypto-currency-code> in <currency>` - To Get Price in Specified Currency\n"
        elif key == "translate":
            message += "`omega translate <phrase to be translated>` - To Get Translate from Foreign Language to English\n"
        elif key == "define":
            message += "`omega define <word>` - To Get Definition of the word\n"
        elif key == "joke":
            message += "`omega joke` - Get a Joke\n"
        elif key == "weather":
            message += "`omega weather <location>` - Get the weather details of the given place\n"
        elif key == "giphy":
            message += "`omega giphy <search word>` - Get a random GIF from Giphy related to the given search word\n"
        elif key == "pnr":
            message += "`omega pnr <valid pnr number>` - Get PNR Details of the Given PNR number\n"
        elif key == "mustread":
            message += "`omega mustread @**<User Mention>** <message>` - Pass Important Messages to Team Members\n"
        elif key == "poll":
            message += "`omega poll create <number of choices> question <question> option <option1> <option2>...` - To Create a New Poll. It will return with a Poll ID Number\n"
            message += "`omega poll vote <POLL_ID> <Choice>` - To Vote for specified option\n"
            message += "`omega poll show all` - List all available polls\n"
            message += "`omega poll show <ID>` - List all details from specified Poll ID\n"
            message += "`omega poll delete all` - Delete All Polls\n"
            message += "`omega poll delete <ID>` - Delete Poll with specified ID\n"
        elif key == "hn" or key == "hackernews":
            message += "`omega hn` OR `omega hackernews` - Show Top 10 stories from Hacker News\n"
        elif key == "motivate":
            message += "`omega motivate` - Get a refreshing and motivating quote\n"
        elif key == "twitter":
            message += "`omega twitter post <tweet>` - Post a Tweet with given tweet\n"
            message += "`omega twitter post_image <image_url> <tweet>` - Post a Tweet with given tweet and image url\n"
        elif key == "screenshot":
            message += "`omega screenshot <website url>` - Take a screenshot of the given url\n"
        elif key == "memo":
            message += "`omega memo <filename>` - Creates a New Memo file and returns its link\n"
        elif key == "cricnews":
            message += "`omega cricnews` - Get top 10 Cricket News\n"
        elif key == "shorturl":
            message += "`omega shorturl <url>` - Get a Shorten URL from goo.gl\n"
        else:
            message = self.help()
            message += "\n{} is not a valid subfield\n".format(key)
        return message

    def process(self, msg):
        content = msg["content"].split()
        sender_email = msg["sender_email"]
        ttype = msg["type"]
        stream_name = msg['display_recipient']
        stream_topic = msg['subject']

        print(content)

        if sender_email == BOT_MAIL:
            return

        print("yeah")

        if content[0].lower() == "omega" or content[0] == "@**omega**":
            if content[1].lower() == "crypto":
                if len(content) > 3 and content[3].lower() == "in":
                    message = self.crypto.get_price(content[2], content[4])
                else:
                    message = self.crypto.get_price(content[2])
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "translate":
                ip = content[2:]
                ip = " ".join(ip)
                message = self.trans.translate(ip)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "define":
                word = content[2].lower()
                result = self.dict_.words(word)
                print(result)
                self.client.send_message({
                    "type":
                    "stream",
                    "subject":
                    msg["subject"],
                    "to":
                    msg["display_recipient"],
                    "content":
                    "**" + word + " means :" + "**" + '\n' + result
                })
            if content[1].lower() == "screenshot":
                result = self.ss.get_ss(content[2])
                print(result)
                self.client.send_message({
                    "type":
                    "stream",
                    "subject":
                    msg["subject"],
                    "to":
                    msg["display_recipient"],
                    "content":
                    "Screenshot taken :wink:\n[Screenshot Link](" + result +
                    ")"
                })
            if content[1].lower() == "joke":
                text = self.joke.tellJoke()
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": text
                })
            if content[1].lower() == "weather":
                place = " ".join(content[2:])
                try:
                    result = self.weather.getWeather(self.geo.convert(place))
                    message = "**" + "Weather update of " + place + "**" + "\n" + "Summary : " + "**" + result[
                        "currently"][
                            "summary"] + "**" + "\n" + "Temparature : " + "**" + str(
                                result["currently"]["temperature"]
                            ) + "**" + '\n' + "Apparent Temparature : " + "**" + str(
                                result["currently"]["apparentTemperature"]
                            ) + "**" + "\n" + "Dew Point : " + "**" + str(
                                result["currently"]["dewPoint"]
                            ) + "**" + "\n" + "Humidity : " + "**" + str(
                                result["currently"]["humidity"]) + "**"
                except KeyError:
                    message = "Weather Info is Not Working Right Now"
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "giphy":
                text = content[2:]
                text = " ".join(text)
                im = str(self.g.search(text))
                message = im[:im.find("?")]
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == 'memo':
                credentials = gdrivesignin.get_credentials()
                http = credentials.authorize(httplib2.Http())
                service = discovery.build('drive', 'v3', http=http)
                file_metadata = {'name': content[2], 'mimeType': "text/plain"}
                file = service.files().create(body=file_metadata,
                                              fields='id').execute()
                web_link = service.files().get(
                    fileId=file['id'],
                    fields="webViewLink").execute()['webViewLink']
                self.client.send_message({
                    "type":
                    "stream",
                    "to":
                    stream_name,
                    "subject":
                    stream_topic,
                    "content":
                    'Memo created.\nView & edit it at: ' + web_link
                })
            if content[1].lower() == "pnr":
                message = self.pnr.get_pnr(content[2])
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "mustread":
                email = self.mustread.get_email(self.client.get_members(),
                                                msg["content"])
                senderusername = self.mustread.get_username(
                    self.client.get_members(), msg["sender_email"])
                print(email)
                self.client.send_message({
                    "type":
                    "private",
                    "to":
                    email,
                    "content":
                    "**" + senderusername +
                    "** mentioned you in must read ! \nThe message says : " +
                    " ".join(content[2:])
                })
            if content[1].lower() == "poll":
                if content[2].lower() == "create":
                    print(",".join(content[4:]))
                    idno = self.poll.create_poll(content[3], content[4:])
                    self.client.send_message({
                        "type":
                        "stream",
                        "subject":
                        msg["subject"],
                        "to":
                        msg["display_recipient"],
                        "content":
                        "Poll Successfully Created and id is : **" +
                        str(idno) + "**"
                    })
                elif content[2].lower() == "show":
                    if content[3].lower() == "all":
                        polldetails = self.poll.show_allpoll()
                        self.client.send_message({
                            "type": "stream",
                            "subject": msg["subject"],
                            "to": msg["display_recipient"],
                            "content": polldetails
                        })
                    else:
                        polldetails = self.poll.show_poll(content[3])
                        self.client.send_message({
                            "type":
                            "stream",
                            "subject":
                            msg["subject"],
                            "to":
                            msg["display_recipient"],
                            "content":
                            "Poll ID: **" + polldetails["id"] +
                            "**\n Question : **" + polldetails["pollname"] +
                            "**\nOption : **" + polldetails["options"] +
                            "**\n Votes : **" + polldetails["votes"] + "**"
                        })
                elif content[2].lower() == "vote":
                    vote = self.poll.vote_poll(content[3], content[4])
                    self.client.send_message({
                        "type":
                        "stream",
                        "subject":
                        msg["subject"],
                        "to":
                        msg["display_recipient"],
                        "content":
                        "Your Vote Has Been Recorded!"
                    })
                elif content[2].lower() == "delete":
                    if content[3].lower() == "all":
                        deleted = self.poll.delete_allpoll()
                        self.client.send_message({
                            "type":
                            "stream",
                            "subject":
                            msg["subject"],
                            "to":
                            msg["display_recipient"],
                            "content":
                            "all polls has been removed from database"
                        })
                    else:
                        deleted = self.poll.delete_poll(content[3])
                        self.client.send_message({
                            "type":
                            "stream",
                            "subject":
                            msg["subject"],
                            "to":
                            msg["display_recipient"],
                            "content":
                            "The given poll has been removed from database"
                        })
            if content[1].lower() == 'motivate':
                quote_data = self.motivate.get_quote()
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": quote_data
                })
            if content[1].lower() == "shorturl":
                short_url = self.shortenedurl.get_shorturl(content)
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": short_url
                })
            if content[1].lower() == 'hackernews' or content[1].lower(
            ) == 'hn' or content[1].lower() == 'HN':
                news = self.hacknews.get_hackernews()
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": news
                })
            if content[1].lower() == "cricnews":
                news = self.cricket.news()
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": news
                })
            if content[1].lower() == "help" and len(content) == 2:
                message = self.help()
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "help" and len(content) > 2:
                subkey = content[2]
                message = self.help_sub(subkey)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "twitter":
                #tweets = self.tw.get()
                #print(tweets)
                if len(content) > 2 and content[2] == "post":
                    if self.tw.stream == msg["display_recipient"]:
                        status = self.tw.post(" ".join(content[3:]))
                        x = json.dumps(status._json)
                        x = json.loads(x)
                        message = "https://twitter.com/{}/status/{}".format(
                            x["user"]["screen_name"], x["id_str"])
                        message = "Tweet Posted\n" + message
                        self.client.send_message({
                            "type": "stream",
                            "subject": msg["subject"],
                            "to": msg["display_recipient"],
                            "content": message
                        })
                    else:
                        message = "Use the stream **{}** to post a tweet".format(
                            self.tw.stream)
                        self.client.send_message({
                            "type": "private",
                            "to": sender_email,
                            "content": message
                        })
                if len(content) > 2 and content[2] == "post_image":
                    if self.tw.stream == msg["display_recipient"]:
                        status = self.tw.post_image(content[3],
                                                    " ".join(content[4:]))
                        if isinstance(status, str):
                            message = status
                        else:
                            x = json.dumps(status._json)
                            x = json.loads(x)
                            message = "https://twitter.com/{}/status/{}".format(
                                x["user"]["screen_name"], x["id_str"])
                            message = "Tweet Posted\n" + message
                        self.client.send_message({
                            "type": "stream",
                            "subject": msg["subject"],
                            "to": msg["display_recipient"],
                            "content": message
                        })
                    else:
                        message = "Use the stream **{}** to post a tweet".format(
                            self.tw.stream)
                        self.client.send_message({
                            "type": "private",
                            "to": sender_email,
                            "content": message
                        })
            if content[1] not in self.subkeys:
                ip = content[1:]
                ip = " ".join(ip)
                message = self.chatbot.get_response(ip).text
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
        if self.urls(" ".join(content)):
            summary = self.w.wiki(" ".join(content))
            if summary:
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": summary
                })
        elif "omega" in content and content[0] != "omega":
            self.client.send_message({
                "type":
                "stream",
                "subject":
                msg["subject"],
                "to":
                msg["display_recipient"],
                "content":
                "Alas! Finally you called me :blush:"
            })
        else:
            return
Exemple #20
0
 def test_second_ball_in_over_count(self):
     self.assertEqual(
         Cricket.increment_balls_bowled_by_bowler(2, {'overs': 0}, 0),
         "0.2")
Exemple #21
0
class ZulipBot(object):
    def __init__(self):
        self.client = zulip.Client(site="https://myra.zulipchat.com/api/")
        self.subscribe_all()
        self.hacknews = Hackernews()
        self.trans = Translate()
        self.movie = Movie()
        self.lyrics = Lyrics()
        self.holiday = Holiday()
        self.currency = Currency()
        self.cricket = Cricket()

        print("done init")
        self.subkeys = [
            "translate", "hackernews", "hn", "hotel", "HN", "askme",
            "cricnews", "movie", "currency", "holiday", "lyrics"
        ]

    def subscribe_all(self):
        json = self.client.get_streams()["streams"]
        streams = [{"name": stream["name"]} for stream in json]
        self.client.add_subscriptions(streams)

    def process(self, msg):
        content = msg["content"].split()
        sender_email = msg["sender_email"]
        ttype = msg["type"]
        stream_name = msg['display_recipient']
        stream_topic = msg['subject']

        print(content)

        if sender_email == BOT_MAIL:
            return

        print("Sucessfully heard.")

        if content[0].lower() == "myra" or content[0] == "@**myra**":
            if content[1].lower() == "translate":
                ip = content[2:]
                ip = " ".join(ip)
                message = self.trans.translate(ip)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "movie":
                ip = content[2:]
                ip = " +".join(ip)
                message = self.movie.about(ip)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })

            if content[1].lower() == "lyrics":
                author = content[2]
                title = content[3:]
                title = " ".join(title)
                message = self.lyrics.about(author, title)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == 'holiday':
                quote_data = self.holiday.holiday()
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": quote_data
                })

            if content[1].lower() == 'currency':
                x = content[2]
                y = content[3]

                quote_data = self.currency.currency(x, y)
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": quote_data
                })

            if content[1].lower() == "cricnews":
                news = self.cricket.news()
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": news
                })

            if content[1].lower() == 'hackernews' or content[1].lower(
            ) == 'hn' or content[1].lower() == 'HN':
                news = self.hacknews.get_hackernews()
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": news
                })

            if content[1] not in self.subkeys:
                ip = content[1:]
                ip = " ".join(ip)
                message = self.chatbot.get_response(ip).text
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })

        elif "myra" in content and content[0] != "myra":
            self.client.send_message({
                "type": "stream",
                "subject": msg["subject"],
                "to": msg["display_recipient"],
                "content": "Hey there! :blush:"
            })
        else:
            return
Exemple #22
0
 def test_sixth_ball_in_over_count(self):
     self.assertEqual(
         Cricket.increment_balls_bowled_by_bowler(6, {'overs': 0}, 0),
         "0.6")
Exemple #23
0
class ZulipBot(object):
    def __init__(self):
        self.client = zulip.Client(site="https://fazeup.zulipchat.com/api/")
        self.subscribe_all()
        self.hacknews = Hackernews()
        self.trans = Translate()
        self.movie = Movie()
        self.lyrics = Lyrics()
        self.holiday = Holiday()
        self.currency = Currency()
        self.cricket = Cricket()
        # self.chatbot.train("chatterbot.corpus.english")
        self.crypto = Crypto()
        self.trans = Translate()
        self.g = Giphy()
        self.w = WikiPedia()
        # self.tw = Twimega()
        # self.motivate = Motivate()
        self.shortenedurl = Urlshortener()
        self.geo = Geocode()
        self.weather = Weather()
        self.dict_ = Dictionary()
        self.joke = Joke()
        self.pnr = Pnr()
        self.mustread = Mustread()
        self.ss = Ss()
        self.cricket = Cricket()
        self.poll = Poll()
        print("done init")
        self.subkeys = [
            "crypto", "translate", "define", "joke", "weather", "giphy", "pnr",
            "mustread", "poll", "hackernews", "hn", "HN", "motivate",
            "twitter", "screenshot", "memo", "cricnews", "help", "shorturl",
            "movie", "currency", "holiday", "lyrics"
        ]

    def subscribe_all(self):
        json = self.client.get_streams()["streams"]
        streams = [{"name": stream["name"]} for stream in json]
        self.client.add_subscriptions(streams)

    def process(self, msg):
        content = msg["content"].split()
        sender_email = msg["sender_email"]
        ttype = msg["type"]
        stream_name = msg['display_recipient']
        stream_topic = msg['subject']

        print(content)

        if sender_email == BOT_MAIL:
            return

        print("Sucessfully heard.")

        if content[0].lower() == "magnus" or content[0] == "@**magnus**":
            if content[1].lower() == "translate":
                ip = content[2:]
                ip = " ".join(ip)
                message = self.trans.translate(ip)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "movie":
                ip = content[2:]
                ip = " +".join(ip)
                message = self.movie.about(ip)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })

            if content[1].lower() == "lyrics":
                author = content[2]
                title = content[3:]
                title = " ".join(title)
                message = self.lyrics.about(author, title)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == 'holiday':
                quote_data = self.holiday.holiday()
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": quote_data
                })

            if content[1].lower() == 'currency':
                x = content[2]
                y = content[3]

                quote_data = self.currency.currency(x, y)
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": quote_data
                })

            if content[1].lower() == "cricnews":
                news = self.cricket.news()
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": news
                })

            if content[1].lower() == 'hackernews' or content[1].lower(
            ) == 'hn' or content[1].lower() == 'HN':
                news = self.hacknews.get_hackernews()
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": news
                })

            if content[1].lower() == "crypto":
                if len(content) > 3 and content[3].lower() == "in":
                    message = self.crypto.get_price(content[2], content[4])
                else:
                    message = self.crypto.get_price(content[2])
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })

            if content[1].lower() == "joke":
                text = self.joke.tellJoke()
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": text
                })

            # if content[1].lower() == 'motivate':
            # 	quote_data = self.motivate.get_quote()
            # 	self.client.send_message({
            # 		"type": "stream",
            # 		"to": stream_name,
            # 		"subject": stream_topic,
            # 		"content": quote_data
            # 		})
            if content[1].lower() == "mustread":
                email = self.mustread.get_email(self.client.get_members(),
                                                msg["content"])
                senderusername = self.mustread.get_username(
                    self.client.get_members(), msg["sender_email"])
                print(email)
                self.client.send_message({
                    "type":
                    "private",
                    "to":
                    email,
                    "content":
                    "**" + senderusername +
                    "** mentioned you in must read ! \nThe message says : " +
                    " ".join(content[2:])
                })

            if content[1].lower() == "pnr":
                message = self.pnr.get_pnr(content[2])
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "screenshot":
                result = self.ss.get_ss(content[2])
                print(result)
                self.client.send_message({
                    "type":
                    "stream",
                    "subject":
                    msg["subject"],
                    "to":
                    msg["display_recipient"],
                    "content":
                    "Screenshot taken :wink:\n[Screenshot Link](" + result +
                    ")"
                })

            if content[1].lower() == "poll":
                if content[2].lower() == "create":
                    print(",".join(content[4:]))
                    idno = self.poll.create_poll(content[3], content[4:])
                    self.client.send_message({
                        "type":
                        "stream",
                        "subject":
                        msg["subject"],
                        "to":
                        msg["display_recipient"],
                        "content":
                        "Poll Successfully Created and id is : **" +
                        str(idno) + "**"
                    })
                elif content[2].lower() == "show":
                    if content[3].lower() == "all":
                        polldetails = self.poll.show_allpoll()
                        self.client.send_message({
                            "type": "stream",
                            "subject": msg["subject"],
                            "to": msg["display_recipient"],
                            "content": polldetails
                        })
                    else:
                        polldetails = self.poll.show_poll(content[3])
                        self.client.send_message({
                            "type":
                            "stream",
                            "subject":
                            msg["subject"],
                            "to":
                            msg["display_recipient"],
                            "content":
                            "Poll ID: **" + polldetails["id"] +
                            "**\n Question : **" + polldetails["pollname"] +
                            "**\nOption : **" + polldetails["options"] +
                            "**\n Votes : **" + polldetails["votes"] + "**"
                        })
                elif content[2].lower() == "vote":
                    vote = self.poll.vote_poll(content[3], content[4])
                    self.client.send_message({
                        "type":
                        "stream",
                        "subject":
                        msg["subject"],
                        "to":
                        msg["display_recipient"],
                        "content":
                        "Your Vote Has Been Recorded!"
                    })
                elif content[2].lower() == "delete":
                    if content[3].lower() == "all":
                        deleted = self.poll.delete_allpoll()
                        self.client.send_message({
                            "type":
                            "stream",
                            "subject":
                            msg["subject"],
                            "to":
                            msg["display_recipient"],
                            "content":
                            "all polls has been removed from database"
                        })
                    else:
                        deleted = self.poll.delete_poll(content[3])
                        self.client.send_message({
                            "type":
                            "stream",
                            "subject":
                            msg["subject"],
                            "to":
                            msg["display_recipient"],
                            "content":
                            "The given poll has been removed from database"
                        })

            if content[1].lower() == "shorturl":
                short_url = self.shortenedurl.get_shorturl(content)
                self.client.send_message({
                    "type": "stream",
                    "to": stream_name,
                    "subject": stream_topic,
                    "content": short_url
                })

            if content[1] not in self.subkeys:
                ip = content[1:]
                ip = " ".join(ip)
                message = self.Chatbot.get_response(ip).text
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })

        elif "magnus" in content and content[0] != "magnus":
            self.client.send_message({
                "type": "stream",
                "subject": msg["subject"],
                "to": msg["display_recipient"],
                "content": "Hey there! :blush:"
            })
        else:
            return
Exemple #24
0
 def test_fifth_ball_in_second_over_count(self):
     self.assertEqual(
         Cricket.increment_balls_bowled_by_bowler(5, {'overs': 1}, 1),
         "1.5")
walltorch_rightbottom.rect.x = 64 * 9
walltorch_rightbottom.rect.y = 64 * 5
walltorch_bottomleft = WallTorch(Character.Direction.DOWN)
walltorch_bottomleft.rect.x = 64 * 3
walltorch_bottomleft.rect.y = 64 * 7
walltorch_bottomright = WallTorch(Character.Direction.DOWN)
walltorch_bottomright.rect.x = 64 * 6
walltorch_bottomright.rect.y = 64 * 7
walltorch_lefttop = WallTorch(Character.Direction.LEFT)
walltorch_lefttop.rect.x = 0
walltorch_lefttop.rect.y = 64 * 2
walltorch_leftbottom = WallTorch(Character.Direction.LEFT)
walltorch_leftbottom.rect.x = 0
walltorch_leftbottom.rect.y = 64 * 5

cricket = Cricket()
cricket.loadSprites()

crabzone = Rect(left_wall.rect.right + 64, top_wall.rect.bottom + 64, right_wall.rect.left - left_wall.rect.width - 128, bottom_wall.rect.top - top_wall.rect.height - 128)
crabspawner = CrabSpawner(crabzone)

hud_space = Rect(0, bottom_wall.rect.bottom, width, height - left_wall.rect.height)
hud = Hud(hud_space)
hud.registerListeners(cricket, crabspawner)

clock = pygame.time.Clock()

#display.fill(blue)
pygame.display.flip()

while 1:
Exemple #26
0
 def test_3_runs_is_odd(self):
     self.assertEqual(Cricket.is_even(3), False)