OGame Automizer Development Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome on the OGame Automizer Development/Support Forum

If this is your first visit, be sure to check out the
http://ogameautomizer.com/doc/manual.html : A guide written by OA users with consultation of OA author (En)

http://ogameautomizer.com/doc/manual_de.html : A guide written by OA users with consultation of OA author (Benutzerschnittstellenhandbuch) (GE)

http://ogameautomizer.com/doc/scripting_manual.html : OA Scripting Manual (En)

Pages: [1] 2 3 ... 7

Author Topic: Send E-Mail if Player send you a Message * UPDATE 3.0 * 18-7-2012  (Read 27279 times)

0 Members and 1 Guest are viewing this topic.

chronos001

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 71
    • View Profile

Hi,
Here my new little script... but you need a little time to set up, for me work :D hehehe

HOW IT WORK:
First, for any reason DH choose to store OGame Message in a folder with HTML File and not in the DB.
I don't known what library for parse HTML are included in OA, then I have made a very little and simple parser based on String and on the File stored by OA.
You need to enable "Store Messages" in OA Message Tab, because when OA save HTML file, the script parse it... if OA don't save messages, the script not send mail  :-\

The most important parameter to Set is:
def htmlAlliance = "Alleanza" // Need to check for ITA, ENG is OK "Alliance"
def htmlTo = "A:"
def htmlDate = "Data:"
def htmlObject = "Oggetto:"
You need to translate in your language, read one message in OGame and write the correct translation.

BE CARREFOUL TO SET ALL PARAMETER CORRECTLY, READ EACH LINE IN SCRIPT, FOR ME WORK GOOD, BUT I CAN NOT TRY IN OTHER LANGUAGE FOR NOW.

Then, when you enable the script, evry "interval" in Minutes, the script read all file in Messages\Your_uni folder (setted by you in config), and if a page contains determinate parameter Script identify if is a PLAYER or normal ogame message.
If is a PLAYER, Script prepare mail, send it to you, copy original file in a Backup folder (setted by you) and then delete original html file from folder. In this way not send the same mail anymore.

FUTURE IMPLEMENTATION:
1. Auto detect language
2. Store Message in a DB and make an accessible way for future script
3. More light cpu usage
4. Any idea... but work is long hihihihi ;D ;D

NOW, TRY THE SCRIPT IF YOU WANT AND WRITE ANY PROBLEM, IF I CAN, I REPLY TO YOU  ::)

1. Added Broadcasting Message parsing
                  - You can choose to enable or disable in config
               2. Ready for SEND SMS (ENABLE ONLY WHEN DH RELASE NEW VERSION OF OA WITH NEW API
                  - You can choose to enable or disable in config
                  - I can't test this function for now


*** EDIT: 18/07/2012 - UPDATED CODE TO 3.0 ***

Code: [Select]
pauseScriptWhenOADisabled()

// ------ SCRIPT BY CHRONOS001 ---------------------------------------------------------

//------- PARAMETER OF HTML TAG ------------------------------------------------------
// For correct use of this script you need to open an HTML File stored in in "Your_OA_Folder\Messages" with an HTML Editor or similar and search for correct TAG in your language
// Ex. for Object Parse you need to search a string like <th scope="row">Object:</th> and write the word Object: in htmlObject def
// IN ALERNATIVE YOU CAN TRY TO SIMPLE OPEN THE HTM FILE AND READ THE CORRECT WORDS IN TOP OF THE PAGE OPENED LIKE THIS:
//From: Comando della Flotta -----> Insert word:  "From:"
//To: xxxxxxx -----> Insert word:  "To:"
//Object: Rapporto di Combattimento [xxxxx] (D: 0, A: 0)  -----> Insert word:  "Object:"
//Date: 02.06.2012 10:54:18  -----> Insert word:  "Date:"

//-------------- CONFIGURATION BY USER -----------------------------------------------

// THIS IS FOR ITALIAN LANGUAGE -> Disable if ENG ENABLED

//def htmlAlliance = "Alleanza"
//def htmlTo = "A:"
//def htmlDate = "Data:"
//def htmlObject = "Oggetto:"

// TRY ENABLE THIS FOR ENGLISH or Uncomment // if using OTHER LANGUAGE DECLARATION BELOW

def htmlAlliance = "Alliance" // Check it in FROM tag on broadcast, for ENG it's OK
def htmlTo = "To:"
def htmlDate = "Date:"
def htmlObject = "Subject:"

//------- PARAMETER OF YOUR EMAIL -----------------------------------

def mailFrom = "your_mail@gmail.com"
def mailTo = "your_mail@gmail.com"
def mailUserName = "your_mail@gmail.com"
def mailPassword = "**********"
def mailSmtp = "smtp.gmail.com"
def smtpPort = 465 // Default is 25, but ex. for gmail is 465
def enableSSL = true // true if your provider use SSL, like GMail else insert false

//------- OTHER SETUP ---- TIMING INTERVAL TO CHECK FOR NEW MESSAGE  -----------------
def sendBroadcastMessage = true  // Send BroadcastMessage true / false (for ITA Messaggi Circolari)
def sendSMS = false  // Send SMS true / false --->> ATTENTION, ENABLE THIS FATURES ONLY WHEN D.H. RELASE THE NEW VERSION OF O.A. WITH THE NEW API
def interval = 10 // In Min --> Time thet Script check for new Messages
// I suggest a time between 5 and 10 minute for not usage too many cpu

//------- END CONFIGURATION BY USER ------- NOTHING BELOW IS USER CONFIGURABLE---------

//------- PARAMETER OF FILE POSITION -------------------------------------------------

// Automatically defined by code below by Devil's Hand

def dirPath = System.getProperty("user.dir")+File.separatorChar+"Messages"+File.separatorChar+getOGameAddress()
new File(System.getProperty("user.dir")+File.separatorChar+"BackupedMessages").mkdir()
new File(System.getProperty("user.dir")+File.separatorChar+"BackupedMessages"+File.separatorChar+getOGameAddress()).mkdir()
def dirBckUp = System.getProperty("user.dir")+File.separatorChar+"BackupedMessages"+File.separatorChar+getOGameAddress()
printOut "Backup message are in: " + dirBckUp

//------- PARAMETER OF FILE POSITION END ----------------------------------------------

//------- DEFINE and PARSE ARRAYS START -------------------------------------------------

def htmlTextAlliance = 'class="tipsPlayer">'
def htmlText = ["note","other","own"] // For the Text I think is not necessary to change
def sTo = "<th scope=\"row\">" + htmlTo + "</th>"
def sDate = "<th scope=\"row\">" + htmlDate + "</th>"
def sObject = "<th scope=\"row\">" + htmlObject + "</th>"
def sText = ["<div class=\"" + htmlText[0] + "\">","<div class=\"" + htmlText[1] + "\">","<div class=\"" + htmlText[2] + "\">"]
def sFrom = '<span class="playerName">'
def br = ['<br>','<p class="other">','<p class="info">','<p class="own">','<p class="note">', '<br />']   
def FileLineRead = []
def makeText = []

def isRead = new int[5] // from, to, date, object, textPL

def setArrayReader = { chkLine ->
    isRead[0] = 0
    isRead[1] = 0
    isRead[2] = 0
    isRead[3] = 0
    isRead[4] = 0

  if (chkLine.contains(sFrom)){
    isRead[0] = 2
    isRead[1] = 0
    isRead[2] = 0
    isRead[3] = 0
    isRead[4] = 0
  }
  if (chkLine.contains(sTo)){
    isRead[0] = 0
    isRead[1] = 2
    isRead[2] = 0
    isRead[3] = 0
    isRead[4] = 0
  }
  if (chkLine.contains(sDate)){
    isRead[0] = 0
    isRead[1] = 0
    isRead[2] = 2
    isRead[3] = 0
    isRead[4] = 0
  }
  if (chkLine.contains(sObject)){
    isRead[0] = 0
    isRead[1] = 0
    isRead[2] = 0
    isRead[3] = 2
    isRead[4] = 0
  }
  if (chkLine.contains(sText[0]) || chkLine.contains(sText[1]) || chkLine.contains(sText[2]) || chkLine.contains(htmlTextAlliance)){ 
    isRead[0] = 0
    isRead[1] = 0
    isRead[2] = 0
    isRead[3] = 0
    isRead[4] = 2
  }
}

def setOutString = { stringToParse, intFrom, intTo ->
  return stringToParse.subSequence(intFrom,intTo)
}

def isPlayer = { textLine -> 
  if (textLine.contains(htmlAlliance)){
    return "AL"
  }
  if (textLine.contains(":")){
    return "PL"
  }
  return "ND"

//------- DEFINE and PARSE ARRAYS END -------------------------------------------------

//-------------- MAIN ------------------
def boolean moreLine = false
def i = 0
def plusLine = 0
def tFrom = ""

while (true){
printOut "Checking for new Player Messages..."
new File(dirPath).eachFile() { sFile ->
  i = 0
  sFile.eachLine{ line ->
    FileLineRead[i] = line
    i++
  }
  setArrayReader("")
  for (k in 0..i-1){   
    readStr = FileLineRead[k].trim()
    if (isRead[0] != 0){
      tFrom = isPlayer(readStr)
      if (tFrom == "PL") {
        s = ~'<'
        m = s.matcher(readStr)
        m.find()
        makeText[0] = "From: " + setOutString(readStr,0,m.start()-1)
        makeText[4] = ""
      } else if (tFrom == "AL") {
               makeText[0] = "From: " + setOutString(readStr,0,readStr.size()-7)
               makeText[4] = ""
             } else {
                 makeText[0] = "NOMAIL"       
                 break
             }
    } 

  if (isRead[1] != 0){makeText[1] = "To: " + setOutString(readStr,4,readStr.size()-5)}
  if (isRead[2] != 0){makeText[2] = "Date: " + setOutString(readStr,4,readStr.size()-5)}
  if (isRead[3] != 0){makeText[3] = "Subject: " + setOutString(readStr,4,readStr.size()-5)}
  if (isRead[4] != 0){
    if (tFrom == "PL") { 
      s = ~'</p>'
    } else if (tFrom == "AL"){
      s = ~'</div>'
      readStr = FileLineRead[k+1].trim()
    }  // <<<<<<------ CHANGED | ... TO HERE
    m = s.matcher(readStr)
    makeText[4] = readStr
    plusLine = 0
    while (!m.find()){
      plusLine +=1
      readStr = FileLineRead[k+plusLine].trim()
      m = s.matcher(readStr)
      makeText[4] = makeText[4] + readStr
    }
    m = s.matcher(makeText[4])
    m.find()
    makeText[4] = setOutString(makeText[4],0,m.start()).trim()
    for (r in 0..5){
      makeText[4] = makeText[4].replaceAll(br[r],' ')
    }
  }
 
  setArrayReader(readStr)
 
}
  if (makeText[0] != "NOMAIL"){
    if (((tFrom == "AL") && (sendBroadcastMessage)) || (tFrom == "PL")){
// ------------ START MAIL SUBROUTINE ------------------------------
      sendEmail(
      mailTo , mailFrom,
  // Change "text in green" if you want to customize your messages. Do not change "\n" (new line)
      "OGame Message Waiting", // Subject:
      "Details of Message: \n" + makeText[0] + "\n" + makeText[1] + "\n" + makeText[2] + "\n" + makeText[3] + "\nText: " + makeText[4],          //core message
  // --------------DO NOT CHANGE BELOW ----------------------------
      mailSmtp, smtpPort,  mailUserName, mailPassword,  enableSSL)
  // --------------- SEND SMS ------------------------------------- 
      if (sendSMS){
        if (sendSMS(mailFrom, mailPassword, "Details of Message: \n" + makeText[0] + "\n" + makeText[1] + "\n" + makeText[2] + "\n" + makeText[3] + "\nText: " + makeText[4])){
          printOut "SMS Sent"
        } else {printOut "Error in SMS Procedure"} 
      }
    } 
// ------------ END MAIL SUBROUTINE --------------------------------

    File srcFile = new File(dirPath + File.separatorChar + sFile.getName())
    File destFile = new File(dirBckUp + File.separatorChar + sFile.getName())
   
    destFile.withDataOutputStream { os-> 
      srcFile.withDataInputStream { is-> 
         os << is 
      } 
    }
    srcFile.delete()
  }
}
sleep (interval*1000*60)
}

*** EDIT: 08/10/2013 Updated by Mec: http://forum.ogameautomizer.com/index.php/topic,2123.msg13974.html#msg13974

Have Fun ;D ;D ;D
« Last Edit: October 08, 2013, 09:21:39 PM by Devil's Hand »
Logged

asdasd

  • Full Member
  • ***
  • Offline Offline
  • Posts: 231
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #1 on: June 08, 2012, 11:28:25 PM »

Script uni****.ogame.*** ------- has been stopped, Throwable: No match available
and not send email i have configurate this like oa email sender.
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #2 on: June 09, 2012, 04:31:01 AM »

There is a problem with cross-platform compatibility

10:26:51 : Checking for new Player Messages...
10:26:54 : Send Mail
10:26:54 : General Error occured while sending email :null
10:26:54 : Script unixx.ogame.xxx xxxxxxxxx has been stopped, Throwable: /Volumes/ramdisk/OGameAutomizer/Messages/unixx.ogame.xxx/\275774723__n_o___s_u_b_j_e_c_t_.html (No such file or directory)

Script creates a file called \275*****_no_subject.....html instead of just 275***....html

Notes:
In this section def dirPath = "/Volumes/ramdisk/OGameAutomizer/Messages/unixx.ogame.xx/" those using OSX or other unix based OS have to use / instead of \
\ is a windows based operator
Same with backup folder path.

Email wont send either.
« Last Edit: June 09, 2012, 04:54:56 AM by Zebra »
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #3 on: June 09, 2012, 05:07:09 AM »

Maybe DH could have a look at this and see where it needs some optimisation, please?
I find the creation of a duplicate folder and deletions disturbing. LOL.

Maybe a better way is to scan for new messages, copy only those messages to the backup folder and then compare Messages folder with backup folder. If a new file appears, then email that out. That way the original Messages folder remains intact.
Logged

chronos001

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 71
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #4 on: June 09, 2012, 09:17:41 AM »

yes... i have test the script only for windows... i need to optimize and test script in other os... its a beta hehehe... now this week i check all... DH help are wlcome...  ;D for other i think when i transfer msg in db is all more simple....   ;D
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #5 on: June 09, 2012, 10:42:46 AM »

Ok. Ive gotten mine to work. These are the changes.

For Unix-based/Mac OSX:
Use / instead of \\
e.g.
def dirPath = "/Volumes/DriveName/ExtraPath/OGameAutomizerFolder/Messages/uniXX.ogame.XX"
def dirBckUp = "/Volumes/DriveName/ExtraPath/OGameAutomizerFolder/MessagesBackup"

Change the \ to / below:
File srcFile = new File(dirPath + '/' + sFile.getName())
File destFile = new File(dirBckUp + '/' + sFile.getName())


And there is some issue with the syntax for the SendEmail. The references doesnt seem to be working.

I'd suggest until its fixed, users use this and replace the entire section. Change the items in green to the relevant data.

sendEmail(
  "your_email@gmail.com", "your_email@gmail.com",  //email addressed to and from
  "Ogame Message Waiting", //Title
    "Details of Message: \n" + makeText[0] + "\n" + makeText[1] + "\n" + makeText[2] + "\n" + makeText[3] + "\n" + makeText[4],          //core message
  "smtp.gmail.com", 465,  //SMTP Server + port
  "your_email@gmail.com", "*********",  //login/email address + passwd
  true  //enableSTARTTLS ?
)

Replace everything between the blue ( ).





« Last Edit: June 09, 2012, 11:02:25 AM by Zebra »
Logged

asdasd

  • Full Member
  • ***
  • Offline Offline
  • Posts: 231
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #6 on: June 09, 2012, 12:36:47 PM »

in windows always this:

Script uni****.ogame.*** ------- has been stopped, Throwable: No match available
 why?
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #7 on: June 09, 2012, 12:45:21 PM »

The directory path is probably wrong. Try look into the backup folder. If there are files inside, copy the files back into the messages folder.
Then check the folder paths.
Try change the // to just /
Eg c://oa/messages instead of all //
Logged

asdasd

  • Full Member
  • ***
  • Offline Offline
  • Posts: 231
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #8 on: June 09, 2012, 01:10:20 PM »

The directory path is probably wrong. Try look into the backup folder. If there are files inside, copy the files back into the messages folder.
Then check the folder paths.
Try change the // to just /
Eg c://oa/messages instead of all //

windows use \ no / i have try
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #9 on: June 09, 2012, 01:11:28 PM »

I meant with one slash instead of two
Logged

asdasd

  • Full Member
  • ***
  • Offline Offline
  • Posts: 231
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #10 on: June 09, 2012, 01:41:22 PM »

I meant with one slash instead of two

no because the javascript read like a comment and no a simple \
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #11 on: June 09, 2012, 01:46:25 PM »

def dirPath = "C:\\OGameAutomizerRD\Messages\uniXXX.ogame.XX"
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #12 on: June 09, 2012, 01:53:21 PM »

@chronos. Something not right. Its sending me dozens of notifications each time.
Logged

Devil's Hand

  • Administrator
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 2,523
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #13 on: June 09, 2012, 02:20:57 PM »

Maybe DH could have a look at this and see where it needs some optimisation, please?

Have already sent a message to chronos about cross platform "issue":
Code: [Select]
def dirPath = "C:\\OGameAutomizerRD\\Messages\\uniXXX.ogame.XX"
def dirBckUp = "C:\\OAMsgBackup\\UNI_XXX"

should be replaced by:
Code: [Select]
def dirPath = System.getProperty("user.dir")+File.separatorChar+"Messages"+File.separatorChar+getOGameAddress()
new File(System.getProperty("user.dir")+File.separatorChar+"BackupedMessages").mkdir()
new File(System.getProperty("user.dir")+File.separatorChar+"BackupedMessages"+File.separatorChar+getOGameAddress()).mkdir()
def dirBckUp = System.getProperty("user.dir")+File.separatorChar+"BackupedMessages"+File.separatorChar+getOGameAddress()

Regards,
Logged

asdasd

  • Full Member
  • ***
  • Offline Offline
  • Posts: 231
    • View Profile
Re: Send E-Mail if Player send you a Message (BETA)
« Reply #14 on: June 09, 2012, 02:59:53 PM »

i have always this :

Script uni****.ogame.*** ------- has been stopped, Throwable: No match available
Logged
Pages: [1] 2 3 ... 7
 

Page created in 0.033 seconds with 20 queries.