Skip to content

Commit d98c96f

Browse files
committed
🌟 Added kotlin
1 parent 166cae8 commit d98c96f

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed

‎kotlin/FuckingCoffee.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.io.BufferedReader
2+
import java.io.InputStreamReader
3+
import java.io.PrintWriter
4+
import java.net.Socket
5+
6+
private const val MY_USERNAME = "my_username"
7+
private const val PASSWORD_PROMPT = "Password: "
8+
private const val PASSWORD = "1234"
9+
private const val COFFEE_MACHINE_IP = "10.10.42.42"
10+
private const val DELAY_BEFORE_BREW = 17
11+
private const val DELAY = 24
12+
13+
fun main(args: Array<String>) {
14+
for (i in 1 until args.size) {
15+
if (!args[i].contains(MY_USERNAME)) {
16+
return
17+
}
18+
}
19+
val telnet = Socket(COFFEE_MACHINE_IP, 23)
20+
val out = PrintWriter(telnet.getOutputStream(), true)
21+
val reader = BufferedReader(InputStreamReader(telnet.getInputStream()))
22+
Thread.sleep((DELAY_BEFORE_BREW * 1000).toLong())
23+
if (reader.readLine() != PASSWORD_PROMPT) {
24+
return
25+
}
26+
out.println(PASSWORD)
27+
out.println("sys brew")
28+
Thread.sleep((DELAY * 1000).toLong())
29+
out.println("sys pour")
30+
out.close()
31+
reader.close()
32+
telnet.close()
33+
}

‎kotlin/Hangover.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import com.twilio.sdk.TwilioRestClient
2+
import com.twilio.sdk.TwilioRestException
3+
import com.twilio.sdk.resource.factory.MessageFactory
4+
import com.twilio.sdk.resource.instance.Message
5+
import org.apache.http.NameValuePair
6+
import org.apache.http.message.BasicNameValuePair
7+
8+
import java.util.ArrayList
9+
import java.util.Random
10+
11+
private val ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID")
12+
private val AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN")
13+
14+
private const val YOUR_NUMBER = "1231231231"
15+
private const val BOSS_NUMBER = "3213213213"
16+
17+
private val randomMessages = arrayOf(
18+
"Locked out",
19+
"Pipes broke",
20+
"Food poisoning",
21+
"Not feeling well"
22+
)
23+
24+
25+
fun main() {
26+
27+
val client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
28+
29+
val finalMessage = randomMessages.random()
30+
31+
val params = ArrayList<NameValuePair>().apply {
32+
add(BasicNameValuePair("Body", "Gonna work from home. $finalMessage"))
33+
add(BasicNameValuePair("From", YOUR_NUMBER))
34+
add(BasicNameValuePair("To", BOSS_NUMBER))
35+
}
36+
37+
val messageFactory = client.getAccount().getMessageFactory()
38+
val message = messageFactory.create(params)
39+
System.out.println(message.getSid())
40+
}
41+

‎kotlin/KumarAsshole.kt

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import java.io.File
2+
import java.io.FileInputStream
3+
import java.util.*
4+
import java.util.regex.*
5+
6+
import javax.mail.*
7+
import javax.mail.internet.*
8+
import javax.mail.search.FlagTerm
9+
10+
//modify below properties to your details
11+
private const val host = "smtp.gmail.com"
12+
private const val username = "[email protected] goes here"
13+
private const val password = "your password goes here "
14+
private const val Kumar_mail = "the mail address to be replied to !"
15+
16+
17+
//Dependencies- Java mail API
18+
fun main() {
19+
val asshole = KumarAsshole()
20+
asshole.read()
21+
}
22+
23+
object KumarAsshole {
24+
25+
fun read() {
26+
val props = Properties()
27+
28+
try {
29+
30+
val session = Session.getDefaultInstance(props, null)
31+
32+
val store = session.getStore("imaps")
33+
store.connect(host, username, password)
34+
35+
val inbox = store.getFolder("inbox")
36+
inbox.open(Folder.READ_ONLY)
37+
38+
val messages = inbox.search(FlagTerm(Flags(Flags.Flag.SEEN), false))
39+
40+
for (i in messages.indices) {
41+
42+
if (messages[i].getFrom()[0].toString().contains(Kumar_mail)) {
43+
44+
var bodytext: String? = null
45+
val content = messages[i].getContent()
46+
if (content is String) {
47+
bodytext = content
48+
49+
} else if (content is Multipart) {
50+
51+
val mp = content as Multipart
52+
53+
val bp = mp.getBodyPart(mp.getCount() - 1)
54+
bodytext = bp.getContent()
55+
56+
}
57+
58+
val pattern = Pattern.compile("sorry|help|wrong", Pattern.CASE_INSENSITIVE)
59+
val matcher = pattern.matcher(bodytext!!)
60+
// check all occurance
61+
62+
if (matcher.find()) {
63+
64+
val props1 = Properties()
65+
val tomail: Array<Address>
66+
67+
val msg = MimeMessage(session)
68+
msg.setFrom(InternetAddress(username))
69+
tomail = messages[i].getFrom()
70+
val t1 = tomail[0].toString()
71+
msg.addRecipient(Message.RecipientType.TO, InternetAddress(t1))
72+
msg.setSubject("Database fixes")
73+
msg.setText("No problem. I've fixed it. \n\n Please be careful next time.")
74+
var t: Transport? = null
75+
t = session.getTransport("smtps")
76+
t!!.connect(host, username, password)
77+
t!!.sendMessage(msg, msg.getAllRecipients())
78+
}
79+
80+
81+
}
82+
}
83+
inbox.close(true)
84+
store.close()
85+
86+
} catch (e: Exception) {
87+
e.printStackTrace()
88+
}
89+
90+
}
91+
}

‎kotlin/SmackMyBitch.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import com.twilio.sdk.TwilioRestClient
2+
import com.twilio.sdk.TwilioRestException
3+
import com.twilio.sdk.resource.factory.MessageFactory
4+
import com.twilio.sdk.resource.instance.Message
5+
import org.apache.http.NameValuePair
6+
import org.apache.http.message.BasicNameValuePair
7+
8+
import java.util.ArrayList
9+
import java.util.Random
10+
11+
//Pre-requisite apache http and twilio java libraries
12+
13+
private const val ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID")
14+
private const val AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN")
15+
16+
private const val YOUR_NUMBER = "1231231231"
17+
private const val HER_NUMBER = "3213213213"
18+
19+
private val randomMessages = arrayOf(
20+
"Working hard",
21+
"Gotta ship this feature",
22+
"Someone fucked the system again"
23+
)
24+
25+
26+
@Throws(TwilioRestException::class)
27+
fun main() {
28+
29+
val client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
30+
31+
val finalMessage = randomMessages.random()
32+
33+
val params = mutableListOf<NameValuePair>().apply {
34+
add(BasicNameValuePair("Body", "Late at work. $finalMessage"))
35+
add(BasicNameValuePair("From", YOUR_NUMBER))
36+
add(BasicNameValuePair("To", HER_NUMBER))
37+
}
38+
39+
val messageFactory = client.getAccount().getMessageFactory()
40+
val message = messageFactory.create(params)
41+
System.out.println(message.getSid())
42+
}

0 commit comments

Comments
 (0)