What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

[REQ] Mail Tracker Addon

uknowwhoibe

New Member
Joined
Sep 17, 2014
Messages
2
Reaction score
0
Greetings,

I'm looking for guidance on making my own addon. I'm familiar with code structures but it seems that it will take me a lot longer without a little bit of help getting started. The addon is fairly simple (I believe).

The addon would do the following:

Add button upon opening mailbox or mail item
If button is pressed, logs (xml, csv, et al.)
  • the sender's name
  • the date/time of message sent (or date/time of button press)
  • the title (subject of mail)
  • the body
  • all item(s) attached (name of item and quantity/quality)
  • Any gold attached

While this may seem simple for some I don't really know where to begin. I have the API documentation open and can navigate through the object list. Can anyone give me some basic framework code to help write this?

Thanks in advance.

@mods - if this is in the wrong section, feel free to move it as I couldn't tell where the best place would be to put it
 
  • the sender's name
  • the date/time of message sent (or date/time of button press)
  • the title (subject of mail)
  • the body
  • all item(s) attached (name of item and quantity/quality)
  • Any gold attached

Hey,

here is some direction for your logging functions

Code:
public void logMails(){
	int i = 0;
	foreach(var mail in getAllMails()){
		//mail contains the data of the mail
		writeLog(i, "sender", mail.sender);
		writeLog(i, "sendDate", mail.sendDate);
		//... add more stuff here [URL="http://archebuddy.com/API/?topic=html/948228360.htm"]Mail[/URL]
		i++;
	}
}

public void writeLog(String sec, String key, String val){
	//search on interwebs for writing to ini file or xml
	//there are tons of libs you can use already
}

If you want a form for it then search on already existing projects, how to create one(my radar plugin uses one) then just add a button to it and attach the logMails() function to it's handler.
For the writeLog function you can find a ton of stuff on web and read some tutorials on this topic. It's not that hard. I think Out also posted some XML writing in his raidstats plugin, you may want to check that one out.
If you need further assistance or some more hints, just msg me in private or post here.
Good luck :)
 
Last edited:
If you want a form for it then search on already existing projects, how to create one(my radar plugin uses one) then just add a button to it and attach the logMails() function to it's handler.
For the writeLog function you can find a ton of stuff on web and read some tutorials on this topic. It's not that hard. I think Out also posted some XML writing in his raidstats plugin, you may want to check that one out.
If you need further assistance or some more hints, just msg me in private or post here.
Good luck :)

How far off am I with this?

Code:
public void logMails(){
	int i = 0;
	foreach(var mail in getAllMails()){
		//mail contains the data of the mail
		writeLog(i, "sender", mail.sender);
		writeLog(i, "sendDate", mail.sendDate);
		writeLog(i, "recDate", mail.openDate);
		writeLog(i, "Title", mail.title);
		writeLog(i, "Body", mail.text);
		writeLog(i, "sentGold", mail.goldAmount);
		writeLog(i, "itemCount", mail.attachments);
			//... I don't see how to loop through the attached items (if there are any) and list the name of the item, quantity and quality...help? here
			// this is wrong
			// int ii = mail.attachments.count
			// foreach(var mail in ii()){
			// writeLog(i, "item", 
			// ii++; 
		i++;
	}
}

public void writeLog(String sec, String key, String val){
	endTime = DateTime.Now;
	
	XmlDocument xmlDoc = new XmlDocument();
	
	XmlNode senderNode = xmlDoc.CreateElement("sender");
    senderNode.InnerText = sender;
    senderNode.AppendChild(senderNode);   
	
	//and so on for sendDate, recDate, Title, Body, sentGold, itemCount, and items
	//am I way off?
	
	xmlDoc.Save(AssemblyDirectory + "\\MailTracker_" + DateTime.Now.ToString("MM'_'dd'_'yyyy_HH'_'mm'_'ss") + ".xml");
	
	public class YourClass : Core
    {               
        private Form f;   
        private Label label;
        private Button buttonStart;
        private Thread formThread;     
        
        private void InitializeForm()
        {
            f = new Form();
            f.Width = 200;
            f.Height = 120;
            f.Text = "Mail Tracker";
            f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            f.MaximizeBox = false;
            f.MinimizeBox = false;
            f.TopMost = true;

            label = new Label();
            label.Left = 8;
            label.Top = 8;
            label.AutoSize = true;
            label.BackColor = Color.Transparent;
            label.Text = "Press Log to log current open mail item.";
            f.Controls.Add(label);
            label.BringToFront();      
            
            
            buttonStart = new Button();
            buttonStart.Left = 50;
            buttonStart.Top = 35;
            buttonStart.Width = 100;
            buttonStart.Height = 25;
            buttonStart.Text = "Log";
            buttonStart.MouseClick += buttonStartMouseClick;
            f.Controls.Add(buttonStart);
                    
        private void buttonStopMouseClick(object sender, MouseEventArgs e)
        {
            dkpStat.CreateXml();
            buttonStart.Enabled = true;
            buttonStop.Enabled = false;  
        }
                     
        private void RunForm()
        {         
            try
            {
                InitializeForm();
                Console.WriteLine("InitializeForm done");
                Application.Run(f);
            }
            catch (Exception error)
            {
                Log(error.ToString());
            }
        }
        
        public void PluginStop()
        {               
            try
            {
                if (f != null)
                {
                    f.Invoke(new Action(() => f.Close()));
                    f.Invoke(new Action(() => f.Dispose()));
                }
                if (formThread.ThreadState == System.Threading.ThreadState.Running)
                {
                    formThread.Abort();
                    formThread.Join();
                }
            }
            catch (Exception error)
            {
                Log(error.ToString());
            }
        }
        
        public void MyEventTest(DoodadObject coffer)
        {
            Console.WriteLine(coffer.name);
        }
        
        public void PluginRun()
        {          
            formThread = new Thread(RunForm);
            formThread.SetApartmentState(ApartmentState.STA);
            formThread.Start();
            while (true)
                Thread.Sleep(100);
        }
    }
}
	
}
 
Code:
public void logMails(){
	int i = 0;
        int k = 0;
        int attachCount = 0;
	foreach(var mail in getAllMails()){
                 attachCount = 0;
                 k = 0;
		//mail contains the data of the mail
		 writeLog(i, "sender", mail.sender);
		 writeLog(i, "sendDate", mail.sendDate);
 		writeLog(i, "recDate", mail.openDate);
		 writeLog(i, "Title", mail.title);
		 writeLog(i, "Body", mail.text);
		writeLog(i, "sentGold", mail.goldAmount);
                attachCount = mail.attachments;
		writeLog(i, "itemCount", attachCount );
                if(attachCount > 0){
                     foreach(var itm in getItems()){
                           //Items here
                           writeLog(i, "ItemAttach" + k , itm.name); // you probably need to rework the log function
                           writeLog(i, "ItemAttach" + k , itm.count); // to make it look better instead of just appending it all to the bottom 
                           //..... 
                           k++;
                     }
                }
		i++;
	}
}

Maybe this gives you a rough idea - didnt look at the XML writing part. You will have to figure that one out on yourself. (Just do a bit of trial and error until you get the wanted results)
 
Back
Top