Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Adding login forwarding via config #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
# a script in whatever language you like. Command names are limited to [0-9a-z].

path = '/usr/share/irccat/'
includeLogin = False

args = sys.argv[1]
bits = args.split(' ')
command = bits[3].lower()
commandIdx = 3
if includeLogin:
commandIdx = 4

command = bits[commandIdx].lower()

found = False
if re.match('^[a-z0-9]+$', command):
Expand Down
5 changes: 5 additions & 0 deletions examples/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
/**
Don't add stupid commands about ponies or paris hilton :)
**/
$includeLogin = false;

$input = $_SERVER['argv'][1];
$toks = explode(" ",$input);
$nick = array_shift($toks);
$channel = array_shift($toks);
$sender = array_shift($toks);
if ($includeLogin) {
$login = array_shift($toks);
}
$first = array_shift($toks);

// switch on first word (the command word)
Expand Down
7 changes: 6 additions & 1 deletion examples/irccat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
<cmdhandler>scripts/cmd_handler.sh</cmdhandler>
<maxresponselines>15</maxresponselines>
</script>


<!-- Settings for extra fields to pass to command handler before command text -->
<fields>
<includelogin>false</includelogin>
</fields>

<!-- Which channels to join on startup -->
<!-- First channel in list is "default channel", and all members are implicitly trusted -->
<channels>
Expand Down
16 changes: 11 additions & 5 deletions src/fm/last/irccat/IRCCat.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class IRCCat extends PircBot {

private String nick;
private String cmdScript;
private boolean includeLogin;
private String defaultChannel = null;
private int maxCmdResponseLines = 26;
private XMLConfiguration config;
Expand Down Expand Up @@ -97,6 +98,7 @@ public IRCCat(XMLConfiguration c) throws Exception {
setEncoding("UTF8");
cmdScript = config.getString("script.cmdhandler");
maxCmdResponseLines = config.getInt("script.maxresponselines", 26);
includeLogin = config.getBoolean("fields.includelogin", false);
nick = config.getString("bot.nick");
setName(nick);
setLogin(nick);
Expand Down Expand Up @@ -130,6 +132,10 @@ public int getCmdMaxResponseLines() {
return maxCmdResponseLines;
}

public boolean getIncludeLogin() {
return includeLogin;
}

protected void onDisconnect(){
while (!isConnected()) {
try {
Expand Down Expand Up @@ -180,7 +186,7 @@ public String getDefaultChannel() {
// PM was sent to us on irc
public void onPrivateMessage(String sender, String login, String hostname,
String message) {
handleMessage(null, sender, message);
handleMessage(null, sender, login, message);
}

public void changeTopic(String target, String topic) {
Expand Down Expand Up @@ -227,7 +233,7 @@ public String mIRCify(String m) {
// message sent to our channel
public void onMessage(String channel_, String sender, String login,
String hostname, String message) {
handleMessage(channel_, sender, message);
handleMessage(channel_, sender, login, message);
}

public void onPart(String _channel, String _sender, String _login,
Expand Down Expand Up @@ -264,7 +270,7 @@ private boolean isTrusted(String n){
return false;
}

public void handleMessage(String channel_, String sender, String message) {
public void handleMessage(String channel_, String sender, String login, String message) {
String cmd;
String respondTo = channel_ == null ? sender : channel_;

Expand Down Expand Up @@ -310,8 +316,8 @@ public void handleMessage(String channel_, String sender, String message) {

// now "cmd" contains the message, minus the address prefix (eg: ?)
// hand off msg to thread that executes shell script
System.out.println("Scripter: ["+respondTo+"] <"+sender+"> "+message);
Thread t = new Scripter(sender, channel_, respondTo, cmd, this);
System.out.println("Scripter: ["+respondTo+"] <"+sender+"> "+message);
Thread t = new Scripter(sender, channel_, respondTo, login, cmd, this);
t.run();
}

Expand Down
13 changes: 9 additions & 4 deletions src/fm/last/irccat/Scripter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@
// hands off cmd to shell script and returns stdout to the requester
class Scripter extends Thread {
IRCCat bot;
String nick, channel, returnName, cmd;
String nick, channel, returnName, login, cmd;

Scripter(String nk, String ch, String r, String c, IRCCat b){
Scripter(String nk, String ch, String r, String l, String c, IRCCat b){
nick = nk;
channel = ch;
login = l;
cmd = c;
returnName = r;
bot = b;
}

public void run(){
try{
String msg = nick + " " + channel + " " + returnName;
if (bot.getIncludeLogin()) {
msg = msg + " " + login;
}
msg = msg + " " + cmd;
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(new String[]{bot.getCmdScript() ,nick + " " + channel + " " + returnName+" "+cmd});
Process process = runtime.exec(new String[]{bot.getCmdScript(), msg});
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader br = new BufferedReader(isr);
Expand All @@ -51,7 +57,6 @@ public void run(){
}catch(Exception e){
e.printStackTrace();
}

}
}