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

91
LINES

< > BotCompany Repo | #1002166 // User Level Bot (C#)

Document

static O mainBot;

public static Dictionary<string, int> UserPostCounts = new Dictionary<string, int>(); 

public static string LevelUp()
{
	string username = cast callOpt(mainBot, "getUserName");

	if (UserPostCounts.ContainsKey(username))
	{
		UserPostCounts[username]++;
		switch (UserPostCounts[username])
		{
			case 10:
				return "Level up! " + username + " is now level 2!";
				break;
			case 100:
				return "Level up! " + username + " is now level 3!";
				break;
			case 500:
				return "Level up! " + username + " is now level 4!";
				break;
			case 1000:
				return "Level up! " + username + " is now level 5!";
				break;
			case 5000:
				return "Level up! " + username + " is now level 6!";
				break;
		}
	}
	else
	{
		UserPostCounts.Add(username, 1);
	}

	return string.Empty;
}

public static string ViewLevel(S s)
{
	string returnString = string.Empty;
	if (match("!level *", s))
	{
		string username = cast callOpt(mainBot, "getUserName");
		int postCount = 0;

		if (UserPostCounts.ContainsKey(username))
		{
			postCount = UserPostCounts[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();
  if (!empty(a)) ret a;
  ret LevelUp();
}

download  show line numbers   

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

No comments. add comment

Snippet ID: #1002166
Snippet name: User Level Bot (C#)
Eternal ID of this version: #1002166/1
Text MD5: 649721dc0fa17b7e4bf9f4f2c3a7886e
Author: stefan
Category:
Type: Document
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-23 00:41:45
Source code size: 1859 bytes / 91 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 513 / 361
Referenced in: [show references]