Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

99
LINES

< > BotCompany Repo | #1002168 // User Level Bot (translated to JavaX)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1467L/9K/31K).

!752

static O mainBot;

p {
  load("UserPostCounts");
}

public static new Map<String, Long> UserPostCounts; 

public static String LevelUp()
{
	String username = cast callOpt(mainBot, "getUserName");
	if (empty(username)) ret null;

	if (UserPostCounts.containsKey(username))
	{
		UserPostCounts.put(username, UserPostCounts.get(username)+1);
    save("UserPostCounts");
    
    S word = "coder maniac";
    
		switch (UserPostCounts.get(username).intValue())
		{
			case 10:
				return "Level up! " + username + " is now a level 2 " + word +"!";
			case 100:
				return "Level up! " + username + " is now a level 3 " + word +"!";
			case 500:
				return "Level up! " + username + " is now a level 4 " + word +"!";
			case 1000:
				return "Level up! " + username + " is now a level 5 " + word +"!";
			case 5000:
				return "Level up! " + username + " is now a level 6 " + word +"!";
		}
	}
	else
	{
		UserPostCounts.put(username, 1L);
    save("UserPostCounts");
	}

	return "";
}

public static String ViewLevel(S s)
{
  new Matches m;
	String returnString = "";
	if (match("!level *", s, m))
	{
		String username = m.unq(0);
		long postCount = 0;

		if (UserPostCounts.containsKey(username))
		{
			postCount = UserPostCounts.get(username);
		}
		else
		{
			return username + " has no posts";
		}

		returnString = username + " is level ";
		if (postCount < 10)
		{
			returnString += "1";
		}
		else if (postCount >= 10 && postCount < 100)
		{
			returnString += "2";
		}
		else if (postCount >= 100 && postCount < 500)
		{
			returnString += "3";
		}
		else if (postCount >= 500 && postCount < 1000)
		{
			returnString += "4";
		}
		else if (postCount >= 1000 && postCount < 5000)
		{
			returnString += "5";
		}
		else
		{
			returnString += "6";
		}
		returnString += " with " + postCount + " posts.";
	}

	return returnString;
}

static synchronized S answer(S s) {
  S a = ViewLevel(s);
  if (!empty(a)) ret a;
  ret LevelUp();
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1198 stefan C# originally by @relevant 2015-12-23 01:04:35

add comment

Snippet ID: #1002168
Snippet name: User Level Bot (translated to JavaX)
Eternal ID of this version: #1002168/1
Text MD5: a49b5334967bbad7fe01458f3ad8dc3a
Transpilation MD5: e9b800ace8a1c97e351d0ccf96d1b304
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-27 18:42:47
Source code size: 2042 bytes / 99 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 940 / 2018
Referenced in: [show references]