Forum Thread: How to Setup an Irc Chat Point Sys

ok this will be going on the fact that you have made an IRC bot before and that you have basic knowledge on c#.

we will be making a .txt database (a folder with lodes of text files) and when we want to get the points, we will open that file then well read the first line turn that into an int (integer) with the Int32.Parse() command in c# System.Net

my Directory will look like this:

.
+-- openircbot
¦ +-- bin
¦ ¦ +-- Debug
¦ ¦ +-- beep-02.wav
¦ ¦ +-- openircbot.exe
¦ ¦ +-- openircbot.exe.mdb
¦ +-- obj
¦ ¦ +-- x86
¦ ¦ +-- Debug
¦ ¦ +-- openircbot.csproj.FilesWrittenAbsolute.txt
¦ ¦ +-- openircbot.exe
¦ ¦ +-- openircbot.exe.mdb
¦ +-- openircbot.csproj
¦ +-- Program.cs
¦ +-- Properties
¦ +-- AssemblyInfo.cs
+-- openircbot.sln
+-- openircbot.userprefs

prep:
first we make the folder im going to make mying in the bin/debig folder
and ill name it point-sys and my program is in the same folder(just essayer)

code:
first we need a timer
DateTime pointTMR = DateTime.Now;
while (true) {

if (DateTime.Now - pointTMR > TimeSpan.FromMinutes (1)) {

}
// extra code
}

there we have a timer now we need a way to read the files
wait a min how will we see the current online users?
if you thought that then good for you
we will need an array a list if you will

string users = new string9999

that will work but we need a way to add users and take users
code:
private string decodeusername(string name){//gets the username
//"name" is just the output stream
try{
int x = name.IndexOf("!");
name = name.Substring (1, x - 1);
return name;
}catch{
}
return null;
}

int userCount = 0;
private void initialusersetup(string Line){//for initial user setup (when you join it will get all current users)
Line = Line.Substring (2);
int x = Line.IndexOf (":");
string allusers = Line.Substring (x);
bool isStillUsers = true;
while (isStillUsers) {
if (allusers == "") {
isStillUsers = false;
} else {
x = allusers.IndexOf (" ");
usersuserCount = allusers.Substring(0,x);
userCount++;
allusers = allusers.Substring (x);
}
}
}

private void removeuser(string user){
if (user.Length > 0) {
for (int x = 0; x < userCount; x++) {
if (users x == user) {
users x = users userCount;
usersuserCount = null;
userCount--;
break;
}
}
}
}

private void adduser(string newuser){
if (newuser.Length > 0) {
for (int x = 0; x < userCount; x++) {
if (users x == null || users x == "") {
users x = newuser;
break;
} else if (x == userCount - 1) {
userCount++;
}
}
}
}

there now we have the add/remove user stuff now we need to get to the adding and removing of points as well as creating files

code:
StreamReader pointreader;
StreamWriter pointwriter;
private void makepointfile(string user){
pointwriter = new StreamWriter (@"point-sys\" + user + ".txt");
pointwriter.Write ("0");
pointwriter.Close ();
}

private void removepoints(int amount,string user){
bool exist = File.Exists (@"point-sys\" + user + ".txt");
if (exist) {
pointreader = new StreamReader (@"point-sys\" + user + ".txt");
string a = pointreader.ReadLine ();
pointreader.Close ();

int points = Int32.Parse (a);
int newpoints = points - amount;

pointwriter = new StreamWriter (@"point-sys\" + user + ".txt");
pointwriter.WriteLine (newpoints);
pointwriter.Close ();

} else {
makepointfile (user);
}
}

private void addpoints(int amount,string user){
bool exist = File.Exists (@"point-sys\" + user + ".txt");
if (exist) {
pointreader = new StreamReader (@"point-sys\" + user + ".txt");
string a = pointreader.ReadLine ();
pointreader.Close ();

int points = Int32.Parse (a);
int newpoints = points + amount;

pointwriter = new StreamWriter (@"point-sys\" + user + ".txt");
pointwriter.WriteLine (newpoints);
pointwriter.Close ();
} else {
makepointfile (user);
}
}

now we can add the point in the timer

code:
if (DateTime.Now - pointTMR > TimeSpan.FromMinutes (1)) {
for (int x = 0; x < userCount; x++) {
if (users x != null) {
addpoints (1, users x);
} else if (x == userCount - 1) {
userCount--;
}
}
}

there took a bit of code but know you can remove,add points
you have a point system that gives points evary 1min
you lernt a bit more c# (i hope)
next ill make a how to make a game on an IRC bot in c#

1 Response

I believe from observation, OTW left because of some gap we are not being told. The shortness of the matter is: He didn't renew his contract with WHT. This should not go hey-wire. Today, it may be a hash tag, tomorrow it will be an operation. That's how all online operations start. I would like you to respect OTW's decision and if anything we should be grateful. Should you need to talk to anyone it would be the management or OTW not the hash tag because I have seen many operations rise up just from a hash tag.

Plus 1 for the tutorial though. Good morning.

# Sergeant

Share Your Thoughts

  • Hot
  • Active