Created
July 20, 2017 04:55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import requests | |
import time | |
import urllib | |
sms_password = "Password123" | |
sms_username = "jhon" | |
nick = "smsbot" | |
network = "127.0.0.1" | |
port = 6667 | |
password = "passwordforIRC" | |
irc = socket.socket() | |
handle = irc.makefile(mode = "rw", buffering = 1, encoding = "utf-8", newline = "\r\n") | |
chan = "#chanirc" | |
irc.connect((network, port)) | |
print("PASS " + password, file = handle) | |
print("NICK " + nick, file = handle) | |
print("USER dfdfdfsd123 0 * :Your Name", file = handle) | |
def parse_message(rawline): | |
"""Helper function to process line from irc""" | |
sender, _, rest = rawline.partition(' ') | |
sender = sender[1:] | |
command, _, rest = rest.partition(' ') | |
args = [] | |
while (len(rest) > 0): | |
if rest[0] == ':': | |
args.append(rest[1:]) | |
break | |
arg, _, rest = rest.partition(' ') | |
args.append(arg) | |
print(arg + ' : ' + rest) | |
return {'sender': sender, 'command': command, 'args': args} | |
def send_command(cmd): | |
print(cmd, file = handle) | |
for line in handle: | |
line = line.strip() | |
print(line.encode("utf-8", "replace")) | |
li = parse_message(line) | |
# if li.command == "PING": | |
# # reply on PING | |
# send_command("PONG :" + li.args.join(" ")) | |
if line[:4].upper() == "PING": | |
send_command("PONG" + line[4:]) | |
elif li.command == "376" or li.command == "422": | |
# END_OF_MOTD / MOTD_NOT_FOUND - when we connected completely to server | |
send_command("JOIN " + chan) | |
elif li.command == "PRIVMSG": | |
# if PRIVMSG to channel 'chan' | |
if li.args[0].upper() == chan.upper(): | |
msg = args[1] | |
if msg.startswith("!sms"): | |
# sender will be nickname | |
sender, _, __ = li.sender.partition('!') | |
_, __, rest = line.partition(' ') | |
number, _, message = rest.partition(' ') | |
# we should check if number is valid, and message is not empty, but we will do it later | |
r = requests.post('"https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0", data={"username": sms_username, "password": sms_password, message: "IRC sms from " + sender + ": " + message, "msisdn": number}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment