robit ... *hic*
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

339 lines
9.1 KiB

package main
import(
"github.com/lrstanley/girc"
"golang.org/x/net/proxy"
"strconv"
"strings"
"net/url"
"bufio"
"time"
"fmt"
"net"
"os"
)
var drinkin []string
var smokin []string
var speedin []string
var vapin []string
var drinkyBoys string
func ircbot() {
soberStrings = []string {
" wakes up confused (sober)",
" sobers up and questions their entire life",
" is straight edge because drugs and alcohol are for LOSERS (sober)",
" doesn't wanna talk about it (sober)",
}
//////////////////////////////////
//////////////////////////////////
///////////////// TCP Server
//inbound, err := net.ListenTCP("tcp", Host+":"+Port) // Define TCP Listener
//if err != nil { //logr.Fatal("RPC Listener error! " + err) }
//psad := new(psadRPC) // Create a new handler of type psadRPC
//rpc.Register(psad)// Adds all relevant functions to RPC registry (gives client options)
//rpc.Accept(inbound) // Begins listening on socket and offering functions
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//logr := //logr.WithContext("IRC")
if (len(os.Args) > 1) {
ircNick = os.Args[1]
}
var SASLbool bool = false
var client *girc.Client
var ircSASL *girc.SASLPlain
fmt.Println("[IRC] Opening auth file for nickserv creds...")
f, err := os.Open("auth.txt")
if err != nil {
fmt.Println("[IRC] Error opening auth.txt file!")
fmt.Println("[IRC] Proceeding without authentication...")
ircUser = ircNick
ircPass = ""
} else {
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Scan()
line := scanner.Text()
auth := strings.Split(line, ":")
ircUser = auth[0]
ircPass = auth[1]
ircSASL = &girc.SASLPlain{User: ircUser, Pass: ircPass}
SASLbool = true
f.Close()
}
if SASLbool == true {
client = girc.New(girc.Config{
Server: ircHost,
Port: ircPort,
Nick: ircNick,
Name: ircNick,
User: ircUser,
SSL: ircSSL,
SASL: ircSASL,
AllowFlood: ircFlood,
Out: os.Stdout,
Version: ircVersion,
})
} else {
client = girc.New(girc.Config{
Server: ircHost,
Port: ircPort,
Nick: ircNick,
Name: ircNick,
User: ircUser,
SSL: ircSSL,
AllowFlood: ircFlood,
Out: os.Stdout,
Version: ircVersion,
})
}
client.Handlers.Add(girc.CONNECTED, func(c *girc.Client, e girc.Event) {
fmt.Println("[IRC] Successfully connected to: " + ircHost)
c.Cmd.Join(ircHome)
fmt.Println("[IRC] Joining channel: " + ircHome)
err = Cowrie(c)
if err != nil {
fmt.Println("[IPC] Error: " + err.Error())
c.Cmd.Message(ircOwner, "IPC Error: err.Error()")
os.Exit(2)
}
})
client.Handlers.Add(girc.INVITE, func(c *girc.Client, e girc.Event) {
c.Cmd.Join(e.Last())
})
client.Handlers.Add(girc.ERR_CANNOTSENDTOCHAN, func(c *girc.Client, e girc.Event) {
Target := ircHome
if (strings.Contains(girc.Fmt(e.String()), ircHome)) {
Target = ircOwner
}
c.Cmd.Message(Target, "ERR_INVITEONLYCHAN:")
c.Cmd.Message(Target, girc.Fmt(e.String()))
})
client.Handlers.Add(girc.ERR_INVITEONLYCHAN, func(c *girc.Client, e girc.Event) {
Phone(c,"ERR_INVITEONLYCHAN:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISUSER, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_WHOISUSER:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISOPERATOR, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_WHOISOPERATOR:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISIDLE, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_WHOISIDLE:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISSERVER, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_WHOISSERVER:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISCHANOP, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_WHOISCHANOP:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISCHANOP, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_LINKS:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISCHANOP, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_STATSLINKINFO:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_WHOISCHANOP, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_TRACELINK:")
Phone(c,girc.Fmt(e.String()))
})
client.Handlers.Add(girc.RPL_TOPICWHOTIME, func(c *girc.Client, e girc.Event) {
Chan := strings.Split(e.String(), " ")[4]
if Chan != ircHome {
Phone(c,"Joined " + Chan + " on " + e.Source.ID())
Phone(c,girc.Fmt(e.String()))
}
})
/* client.Handlers.Add(girc.RPL_NAMREPLY, func(c *girc.Client, e girc.Event) {
reply := strings.Split(e.String(), " ")
if reply[5] != ircHome {
for i, h := range reply {
if i < 4 { continue }
Phone(c,h)
}
} else {
ircBanner(c)
Phone(c,ircVersion)
}
})*/
client.Handlers.Add(girc.RPL_WHOISCHANNELS, func(c *girc.Client, e girc.Event) {
Phone(c,"RPL_WHOISCHANNELS:")
Phone(c,e.String())
})
client.Handlers.Add(girc.PRIVMSG, func(c *girc.Client, e girc.Event) {
Sender := e.Source.Name
if Sender == "NickServ" {
fmt.Println("[IRC] NickServ response: " + e.Last())
}
if (strings.HasPrefix(e.Last(), ".")) {
fmt.Println("[IRC] "+e.String())
thyWill := strings.Split(e.Last(), " ")
switch thyWill[0] {
case ".whois":
if len(thyWill) == 1 {
c.Cmd.ReplyTo(e, girc.Fmt("Usage: !whois nick"))
return
}
fmt.Println("[IRC] <"+string(Sender)+"> !spider " + thyWill[1])
if girc.IsValidNick(thyWill[1]) {
c.Cmd.Whois(thyWill[1])
return
} else {
fmt.Println("[IRC] ERROR: Bad whois target!")
Phone(c,"Bad Target! Wtf is that shit?")
return
}
case ".spider":
if Sender != ircOwner {
c.Cmd.Kick(ircHome,Sender,"lol r3kt")
return
}
thyWill := strings.Split(e.Last(), " ")
var thyMark string
if len(thyWill) == 1 {
c.Cmd.ReplyTo(e, girc.Fmt("Usage: !spider #channel"))
return
}
thyMark = thyWill[1]
fmt.Println("[IRC] <"+string(Sender)+"> !spider " + thyMark)
if girc.IsValidChannel(thyMark) {
fmt.Println("[IRC][SPIDER] Joining target " + thyMark)
Phone(c,"Joining " + thyMark)
c.Cmd.Join(thyMark)
return
} else {
fmt.Println("[IRC][SPIDER] Bad scan target! " + thyMark)
Phone(c,"Bad Target! Wtf is that shit?")
return
}
case ".stop":
if Sender == ircOwner {
c.Close()
return
} else {
c.Cmd.Kick(ircHome,Sender,"yeah okay retard")
}
case ".motd":
ircBanner(c)
case ".cowrie":
if (len(thyWill) < 3) {
cowSay(c,"snail","snailyboi","Cowrie is disabled on this instance, but i hope you like this cute snail :)")
return
}
case ".drinkin":
if !contains(drinkin,Sender) {
fmt.Println("[IRC][drinkin] New drinker! " + Sender)
drinkin = append(drinkin, Sender)
} else {
fmt.Println("[IRC][drinkin] Existing drinker " + Sender)
drinkyBoys = strings.Join(drinkin, " ")
drinkyBoys = strings.Replace(drinkyBoys, "nil", "", -1)
drinkyBoys = strings.Replace(drinkyBoys, " ", "", -1)
Phone(c, Sender + " takes another swig ;D")
Phone(c, " 🍺 ------> " + drinkyBoys)
return
}
ircDrinkin(c)
drinkyBoys = strings.Join(drinkin," ")
drinkyBoys = strings.Replace(drinkyBoys, "nil ", "", -1)
drinkyBoys = strings.Replace(drinkyBoys, " ", "", -1)
Phone(c," -------> "+drinkyBoys)
case ".sober":
if contains(drinkin,Sender) {
for i, v := range drinkin {
if v == Sender {
drinkin[i] = "nil"
}
}
}
Phone(c, Sender + soberString())
default:
fmt.Println("[IRC] Unknown bot command issued: " + thyWill[0])
}
}
})
sslString := " "
////logr.Debug("Parsing proxy URI: " + ProxyURI)
//logr.Debug("Validating " + proxyProto + " proxy at host " + proxyHost + " on port " + proxyPort)
if ircSSL == true {
sslString = "-ssl"
}
if proxyProto != "false" {
ProxyUrl, err := url.Parse(proxyProto + "://" + proxyHost + ":" + proxyPort)
if err != nil {
fmt.Println("Proxy URI is malformed!")
panic(err)
}
dialer, _ := proxy.FromURL(ProxyUrl, &net.Dialer{Timeout: 5 * time.Second})
for {
fmt.Println("[IRC] Dialing through a " + proxyProto + " proxy at host " + proxyHost + " on port " + proxyPort)
fmt.Println("[IRC] Connecting to " + ircHost + "/" + strconv.Itoa(ircPort) + " " + sslString)
if err := client.DialerConnect(dialer); err != nil {
fmt.Println("[IRC] Connection error! " + err.Error())
fmt.Println("[IRC] reconnecting...")
time.Sleep(1)
} else {
return
}
}
} else {
for {
fmt.Println("[IRC] Connecting to " + ircHost + "/" + strconv.Itoa(ircPort) + " " + sslString)
if err := client.Connect(); err != nil {
fmt.Println("[IRC] Connection error! " + err.Error())
fmt.Println("[IRC] reconnecting...")
time.Sleep(1)
} else {
return
}
}
}
}