Skip to main content

Getting a Hey Invite Code using a Twitter Bot

I usually keep a template at my disposal for these hunts. If you haven't read my previous blog post already, I highly recommend you do so. It gives a nice introduction to creating your first app on Twitter and your getting your first bot up and running.

Before starting to code, I first spent some time examining what keywords/phrases people used when discussing Hey. I kept track of those keywords and realized the most popular ones were the following:

['hey invite', 'hey code', '#hey', 'hey.com']

I then discovered that Hey invite codes were 7 character alphanumeric strings, so I created a regex pattern that can be used to match possible codes in tweets:

/\b[A-z0-9]{7}\b/g

Obviously this isn't perfect; if there are words that are 7 characters, it will match those unwanted words. I was fine with some manual labor.

After this research phase, I decided to whip out my Twitter-bot-invite-code-hunter (yes, this is what I call it). It utilizes the Twit library to use Twitter's API with ease. The initial setup includes importing the library and setting up the keys for your app:

var Twit = require('twit');
var T = new Twit({
    consumer_key:         '...',
    consumer_secret:      '...',
    access_token:         '...',
    access_token_secret:  '...',
})

After that, we can use streams to listen to new tweets while tracking specific keywords, namely, the ones I mentioned above:

var stream = T.stream('statuses/filter', { track: ['hey invite', 'hey code', '#hey', 'hey.com'] });

After this is done, we listen to this stream on every new tweet as follows:

stream.on('tweet', function (tweet) {
})

Now we have a tweet object. To learn more about what attributes these objects have, I recommend you check out Twitter's official documentation on Tweet objects at https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/tweet-object.

It turns out tweet has an attribute called text, which as the name suggests, contains the text of the tweet. Now, we can match it against our regex pattern as follows:

match_res = tweet.text.match(/\b[A-z0-9]{7}\b/g)

match_res now contains the words that match the criteria we need. We can then do the following:

console.log(tweet.text)
if (match_res != null) {
    console.log("IMPORTNAT: " + match_res)
    console.log("")
}
console.log("")

This will check if any words matched, and if they did then it'll print them out. Aaaand that's pretty much it. The bot is ready to run.

🤑 Was it successful?

I was really hoping it would be as easy as getting those Fortnite and CoD codes (those took less than 5 minutes). Sadly, I waited for over 2 hours for this to work because the codes started pouring out when new Hey invites were sent out.

After about 2 hours of waiting I saw someone who tweeted a code, I was really excited so I quickly opened Hey and put in the code and it worked!!

Comments

Popular posts from this blog

4 Ways to Communicate Across Browser Tabs in Realtime

1. Local Storage Events You might have already used LocalStorage, which is accessible across Tabs within the same application origin. But do you know that it also supports events? You can use this feature to communicate across Browser Tabs, where other Tabs will receive the event once the storage is updated. For example, let’s say in one Tab, we execute the following JavaScript code. window.localStorage.setItem("loggedIn", "true"); The other Tabs which listen to the event will receive it, as shown below. window.addEventListener('storage', (event) => { if (event.storageArea != localStorage) return; if (event.key === 'loggedIn') { // Do something with event.newValue } }); 2. Broadcast Channel API The Broadcast Channel API allows communication between Tabs, Windows, Frames, Iframes, and  Web Workers . One Tab can create and post to a channel as follows. const channel = new BroadcastChannel('app-data'); channel.postMessage(data); And oth...

Certbot SSL configuration in ubuntu

  Introduction Let’s Encrypt is a Certificate Authority (CA) that provides an easy way to obtain and install free  TLS/SSL certificates , thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, Certbot, that attempts to automate most (if not all) of the required steps. Currently, the entire process of obtaining and installing a certificate is fully automated on both Apache and Nginx. In this tutorial, you will use Certbot to obtain a free SSL certificate for Apache on Ubuntu 18.04 and set up your certificate to renew automatically. This tutorial will use a separate Apache virtual host file instead of the default configuration file.  We recommend  creating new Apache virtual host files for each domain because it helps to avoid common mistakes and maintains the default files as a fallback configuration. Prerequisites To follow this tutorial, you will need: One Ubuntu 18.04 server set up by following this  initial ...

Working with Node.js streams

  Introduction Streams are one of the major features that most Node.js applications rely on, especially when handling HTTP requests, reading/writing files, and making socket communications. Streams are very predictable since we can always expect data, error, and end events when using streams. This article will teach Node developers how to use streams to efficiently handle large amounts of data. This is a typical real-world challenge faced by Node developers when they have to deal with a large data source, and it may not be feasible to process this data all at once. This article will cover the following topics: Types of streams When to adopt Node.js streams Batching Composing streams in Node.js Transforming data with transform streams Piping streams Error handling Node.js streams Types of streams The following are four main types of streams in Node.js: Readable streams: The readable stream is responsible for reading data from a source file Writable streams: The writable stream is re...