Help with automatic booting of looters.

HasteBro

Member
Continuing my journey to make an awesome clanbot, I'm now working on booting clannies that were added to our looter rank. Here's what I came up with (this uses MrEdge's clan admin functions, so I won't put the whole thing here):

PHP:
string clanniepage = visit_url("showplayer.php?who="+CurrentRoster[Clannie].ID);
				matcher ISdate = create_matcher("<br>Title: <b>(.*?)\\.(.*?)\\.(.*?) at (.*?):(.*?):(.*?) (.*?)</b>", clanniepage);
				matcher DateNow = create_matcher("(.*?)\\.(.*?)\\.(.*?)", now_to_string("yyyy.MM.dd"));
				
				find(ISdate);
				find(DateNow);
				
				int[int]ISputMod;
				ISputMod[1] = 8
				ISputMod[2] = 9
				ISputMod[3] = 10
				ISputMod[4] = 11
				ISputMod[5] = 12
				ISputMod[6] = 13
				ISputMod[7] = 14
				ISputMod[8] = 15
				ISputMod[9] = 16
				ISputMod[10] = 17
				ISputMod[11] = 18
				ISputMod[12] = 19
				ISputMod[13] = 20
				ISputMod[14] = 21
				ISputMod[15] = 22
				ISputMod[16] = 23
				ISputMod[17] = 24
				ISputMod[18] = 25
				ISputMod[19] = 26
				ISputMod[20] = 27
				ISputMod[21] = 28
				ISputMod[22] = 29
				ISputMod[23] = 30
				ISputMod[24] = 31
				ISputMod[25] = 1
				ISputMod[26] = 2
				ISputMod[27] = 3
				ISputMod[28] = 4
				ISputMod[29] = 5
				ISputMod[30] = 6
				ISputMod[31] = 7
				
				int ISput = to_int(group(ISdate, 3));
				if (ISputMod contains ISput)
				{
					int BANdate = (ISputMod[ISput]);
				}
				
				if(BANdate == to_int(group(DateNow, 3)))
				{
					print(Clannie+ " is being booted due to not raising his karma after 1 week.", "red");
					visit_url("clan_members.php?&action=modify&pids[]=" +CurrentRoster[Clannie].ID+ "&level" +CurrentRoster[Clannie].ID+ "=" +GetRankID(IS, MemberPage)+ "&title" +CurrentRoster[Clannie].ID+ "=" +IS+ "&boot" +CurrentRoster[Clannie].ID+ "&modify=Modify Members");
					kmail(to_string(CurrentRoster[Clannie].ID), ISban, 0);
					chat_private("HastyBuffer", "BlackList Add " +Clannie+ "");
					print(Clannie+ " was successfully booted and added to the Black List.", "purple");
					kmail("HasteBro", to_string(Clannie)+" was booted due to being IS and not raising his karma. Timestamp: "+ now_to_string("yyyy.MM.dd 'at' HH:mm:ss z") +"", 0);
				}

I got it working all right with a previous version that didn't use a map (and had problems when ISput was equal to 25 to 31), but I ran out of looters to test this version on. So what I want to know is if using "ISputMod[ISput]" like that will work.

Also, there's still a problem with months that have only 30 days (24 to 30 would need different values on those), as well as the month of February, so is there something that can be done with those cases?

Also also, is there an alternative to using a map that makes the whole thing more compact?
 

xKiv

Active member
I think you want modulo - something like (for a 31-day month)
Code:
ISputMod[ISput] = ((ISput-24) % 31)+1;

---
This won't work (and the script shouldn't even compile):
Code:
                if (ISputMod contains ISput)
                {
                    int BANdate = (ISputMod[ISput]);
                } 
// using BANdate here
You need to declare BANdate outside that block. You should also have an else branch in case ISput is *not* in ISputMod.
(which is moot, because that part would go out of the window and be replaced by int BANdate = ((ISput-24) % (monthLength))+1)
 
Last edited:

HasteBro

Member
xKiv:
The only problem with that modulo was it returns negative values for anything below 23, so changing it to +7 was what I needed, thanks for the tip =)

heeheehee:
Doesn't datediff return the number of days between 2 dates? I already know that info (it's 7 days between being put in the looter rank and banning if conditions are not met). Or is there another use I'm not seeing there?


EDIT: heeheehee, I do see how it would be used actually, but it would mean having to declare each date for each month in the map, and that's a bit too much. So I came up with an alternative solution:

PHP:
				string clanniepage = visit_url("showplayer.php?who="+CurrentRoster[Clannie].ID);
				matcher ISdate = create_matcher("<br>Title: <b>(.*?)\\.(.*?)\\.(.*?) at (.*?):(.*?):(.*?) (.*?)</b>", clanniepage);
				matcher DateNow = create_matcher("(.*?)\\.(.*?)\\.(.*?)", now_to_string("yyyy.MM.dd"));
				int BANdate;
				int dateMod;
												
				find(ISdate);
				find(DateNow);
				
				switch (to_int(group(ISdate, 2)))
				{
					case(1): dateMod = 31; break;
					case(3): dateMod = 31; break;
					case(5): dateMod = 31; break;
					case(7): dateMod = 31; break;
					case(8): dateMod = 31; break;
					case(10): dateMod = 31; break;
					case(12): dateMod = 31; break;
					case(4): dateMod = 30; break;
					case(6): dateMod = 30; break;
					case(9): dateMod = 30; break;
					case(11): dateMod = 30; break;
					case(2): dateMod = 28; break;
				}
				
				int ISput = to_int(group(ISdate, 3));
				
				int[int]ISputMod;
				ISputMod[ISput] = ((ISput+7)+1 % dateMod);
				
				if (ISputMod contains ISput)
				{
					BANdate = (ISputMod[ISput]);
				}
				else
				{
					break;
				}
				
				if(BANdate == to_int(group(DateNow, 3)))
				{
					print(Clannie+ " is being booted due to not raising his karma after 1 week.", "red");
					visit_url("clan_members.php?&action=modify&pids[]=" +CurrentRoster[Clannie].ID+ "&level" +CurrentRoster[Clannie].ID+ "=" +GetRankID(IS, MemberPage)+ "&title" +CurrentRoster[Clannie].ID+ "=" +IS+ "&boot" +CurrentRoster[Clannie].ID+ "&modify=Modify Members");
					kmail(to_string(CurrentRoster[Clannie].ID), ISban, 0);
					chat_private("HastyBuffer", "BlackList Add " +Clannie+ "");
					print(Clannie+ " was successfully booted and added to the Black List.", "purple");
					kmail("HasteBro", to_string(Clannie)+" was booted due to being IS and not raising his karma. Timestamp: "+ now_to_string("yyyy.MM.dd 'at' HH:mm:ss z") +"", 0);
				}

This would work with the exception of leap years (which I can deal with that manually if needed), right?
 
Last edited:

heeheehee

Developer
Staff member
You don't need to stick all the dates in a map if you parse the date and compare it to the current date.

So something like
Code:
string clanniepage = visit_url("showplayer.php?who="+CurrentRoster[Clannie].ID);
matcher ISdate = create_matcher("<br>Title: <b>(.*?)\\.(.*?)\\.(.*?) at (.*?):(.*?):(.*?) (.*?)</b>", clanniepage);
find(ISdate);
if (datediff(today_to_string(), ISdate.group(1) + ISdate.group(2) + ISdate.group(3)) >= 7) {
    // do stuff
}

assuming that the title is in the form yyyy.MM.dd
 
Top