ViewClasses, ViewClassUser
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

ViewClasses, ViewClassUser

Started by frankyk, 16 April, 2004, 00:55:45

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

frankyk

Hi,

I was wondering if someone could write a script that would allow a user to type the following commands:

+viewclasses : Views users that registered for

+viewschedule : Views selected users class schedule

+addclass : Adds a class to users schedule which will also add that class to the overall class list.

So basically, a person would type like +addclass Psych 60 11:00am and it would add the class to a textfile that everyone can read.  When someone types +viewclasses Psych60 it will show Psych 60 users at all times possible.

Thank you for your time!

frankyk


nErBoS

Hi,

Not understanding your request, the script you want it?s to add class of users ??? What is the objective ??

Best regards, nErBoS
--## nErBoS Spot ##--

frankyk

people that use the hub go to school and i just want people to be able to see who has the same classes with each other.

Like you know, who is taking history class, how many people are taking it, at what time, etc.

Basically, it's a database to keep track of who is which class so if people want to meet up, they can do that.

nErBoS

Hi,

Sorry for the delay on the script but i am having a lot of work. Question, when you want to see the class there are user on it, is that you that write them ??? If yes you will want a file to each classes, right ???

Best regards, nErBoS
--## nErBoS Spot ##--

frankyk

Hi,

No worries, thanks for doing this :D.

As for your question, I want a user to be able to enter a command and this command will write to a public file available for everyone to view.  So, if that means writing to the file that is also being viewed, yes.

Basically something like this:

+addclass Psychology1 9:00AM

writetofile myclass.dat
writetofile Psychology.dat (add username to Psychology.dat)
writetofile Allclass.dat (add total users per class)

+viewclass Psychology1 9:00AM

openfile Psychology.dat

Which looks like this:
--------------------------------
Psychology1 @ 9:00 AM

nickname1
nickname2
nickname3

+viewallclasses

openfile Allclass.dat

While looks like this:
---------------------------
Psychology1 @ 9:00 AM (5 students)
Economics1 @ 10:00 AM (1 student)
Accounting1 @ 9:00 AM (20 students)

+viewschedule nickname

openfile myclass.dat

Which looks like this:
----------------------------
Nickname1 is enrolled in the following classes:

Psychology1 @ 9:00 AM
Economics1 @ 10:00 AM
Calculus1 @ 5:00 PM

It's a little complicated and a little confusing, but that's basically the style I want I guess.  Thank you =).

nErBoS

Hi,

Thanks for the fine explanion, will start to work on it at soon as i can.

Best regards, nErBoS
--## nErBoS Spot ##--

nErBoS

Hi,

Try out this one...

--Requested by frankyk
--Made by nErBoS

sBot = "Principal"

allclass = "Allclass.dat"	--This file will be created, contains all names and schedule of classes

function OnExit()
end

function Main()
	frmHub:RegBot(sBot)
end

function DataArrival(user, data)
	if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
		data = strsub(data,1,strlen(data)-1)
		s,e,cmd = strfind(data, "%b<>%s+(%S+)")
		if (cmd == "+helpclass") then
			local sTmp = ""
			sTmp = sTmp.."#### Class Commands ####\r\n\r\n"
			sTmp = sTmp.."+addclass  \tCreate's a Class and add's your nick, if the class exist will add only the nick\r\n"
			sTmp = sTmp.."+viewclasses\t\t\t\tShows All Classes and there schedule\r\n"
			sTmp = sTmp.."+viewclass \t\t\tShow the class and the users that were on it\r\n"
			sTmp = sTmp.."+viewschedule \t\t\tShow the class that the nick is in\r\n"
			user:SendPM(sBot, sTmp)
			return 1
		elseif (cmd == "+addclass") then
			local s,e,class,schd = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
			if (class == nil or schd == nil) then
				user:SendPM(sBot, "Syntax Error, +addclass  , you must write a class name and schedule.")
			else
				AddClass(user, class, schd)
				user:SendPM(sBot, "Done.")
			end
			return 1
		elseif (cmd == "+viewclasses") then
			OpenAllClass(user)
			return 1
		elseif (cmd == "+viewclass") then
			local s,e,class = strfind(data, "%b<>%s+%S+%s+(%S+)")
			if (class == nil) then
				user:SendPM(sBot, "Syntax Error, +viewclass , you must write a class name.")
			else
				ViewClass(user, class)
			end
			return 1
		elseif (cmd == "+viewschedule") then
			local s,e,usr = strfind(data, "%b<>%s+%S+%s+(%S+)")
			if (usr == nil) then
				user:SendPM(sBot, "Syntax Error, +viewschedule , you must write a nick.")
			else
				ViewUser(user, usr)
			end
			return 1
		end
	end
end

function AddClass(user, class, schedule)
	local sLine = ""
	local time = 0
	local myclass = strlower(user.sName)..".dat"
	local cl = strlower(class)
	cl = cl..".dat"

	-------------Add To User.dat-------------
	if (readfrom(myclass) == nil) then
		writeto(myclass)
		write(class.." @ "..schedule)
		writeto()
	else
		readfrom(myclass)
		while 1 do
			local line = read()
			if (line == nil) then
				sLine = sLine..class.." @ "..schedule
				break
			else
				sLine = sLine..line.."\r\n"
			end
		end
		readfrom()
		writeto(myclass)
		write(sLine)
		writeto()
		sLine = ""
	end

	-------------Add To Class.dat-------------
	if (readfrom(cl) == nil) then
		sLine = sLine.."sche= "..schedule.."\r\n"
		sLine = sLine..user.sName
		writeto(cl)
		write(sLine)
		writeto()
		sLine = ""
	else
		readfrom(myclass)
		while 1 do
			local line = read()
			if (line == nil) then
				if (time == 0) then
					sLine = sLine..user.sName
				end
				break
			else
				local s,e,nickname = strfind(line, "(%S+)")
				if (strlower(user.sName) == strlower(nickname)) then
					time = 1
				end
				sLine = sLine..line.."\r\n"
			end
		end
		readfrom()
		writeto(myclass)
		write(sLine)
		writeto()
		sLine = ""
		time = 0
	end

	-------------Add To AllClass.dat-------------
	if (readfrom(allclass) == nil) then
		writeto(allclass)
		write(class.." "..schedule.." 1")
		writeto()
	else
		readfrom(allclass)
		while 1 do
			local line = read()
			if (line == nil) then
				if (time == 0) then
					sLine = sLine..class.." "..schedule.." 1"
				end
				break
			else
				local s,e,clss,schd,number = strfind(line, "(%S+)%s+(%S+)%s+(%S+)")
				if (strlower(clss) == strlower(class)) then
					number = tonumber(number) + 1
					sLine = sLine..clss.." "..schd.." "..number.."\r\n"
					time = 1
				else
					sLine = sLine..line.."\r\n"
				end
			end
		end
		readfrom()
		writeto(allclass)
		write(sLine)
		writeto()
		sLine = ""
		time = 0
	end
end

function OpenAllClass(user)
	local sLine = ""
	if (readfrom(allclass) == nil) then
		sLine = "There is no Class in the file AllClass.dat."
	else
		sLine = sLine.."### All Class ###\r\n\r\n"
		readfrom(allclass)
		while 1 do
			local line = read()
			if (line == nil) then
				break
			else
				local s,e,clss,schd,number = strfind(line, "(%S+)%s+(%S+)%s+(%S+)")
				if (clss ~= nil and schd ~= nil and number ~= nil) then
					sLine = sLine..clss.." @ "..schd.." ("..number.." Students)\r\n"
				end
			end
		end
		readfrom()
	end
	user:SendPM(sBot, sLine)
end

function ViewClass(user, class)
	local sLine = ""
	local cl = strlower(class)
	cl = cl..".dat"
	if (readfrom(cl) == nil) then
		sLine = "That Class does not exist."
	else
		readfrom(cl)
		while 1 do
			local line = read()
			if (line == nil) then
				break
			else
				local s,e,usr = strfind(line, "(%S+)")
				if (usr ~= nil) then
					if (usr == "sche=") then
						local s,e,schd = strfind(line, "%S+%s+(%S+)")
						sLine = sLine.."### "..class.." @ "..schd.." ###\r\n\r\n"
					else
						sLine = sLine..usr.."\r\n"
					end
				end
			end
		end
		readfrom()
	end
	user:SendPM(sBot, sLine)
end

function ViewUser(user, usr)
	local sLine = ""
	local myclass = strlower(usr)..".dat"
	if (readfrom(myclass) == nil) then
		sLine = "That User does not exist."
	else
		sLine = sLine.."### User Schedule ###\r\n\r\n"
		readfrom(myclass)
		while 1 do
			local line = read()
			if (line == nil) then
				break
			else
				sLine = sLine..line.."\r\n"
			end
		end
		readfrom()
	end
	user:SendPM(sBot, sLine)
end

Best regards, nErBoS
--## nErBoS Spot ##--

frankyk

#8
Thanks Nerbos!  Can you also make a +delclass

nErBoS

Hi,

Ok, when i get a free time i will see that.

Best regards, nErBoS
--## nErBoS Spot ##--

frankyk


nErBoS

Hi,

Sorry frankyk for the delay this week is the academic week in Portugal, there for i will be out of home and when i am at home i will be drunk :p

In the weekend i will do that request.

Best regards, nErBoS
--## nErBoS Spot ##--

nErBoS

Hi,

Sorry for the delay, here is the script fixed and added the +delclass...

--Requested by frankyk
--Made by nErBoS

sBot = "Principal"

allclass = "Allclass.dat"	--This file will be created, contains all names and schedule of classes

function OnExit()
end

function Main()
	frmHub:RegBot(sBot)
end

function DataArrival(user, data)
	if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
		data = strsub(data,1,strlen(data)-1)
		s,e,cmd = strfind(data, "%b<>%s+(%S+)")
		if (cmd == "+helpclass") then
			local sTmp = ""
			sTmp = sTmp.."#### Class Commands ####\r\n\r\n"
			sTmp = sTmp.."+addclass   \tCreate's a Class and add's your nick, if the class exist will add only the nick\r\n"
			sTmp = sTmp.."+viewclasses\t\t\t\tShows All Classes and there schedule\r\n"
			sTmp = sTmp.."+viewclass  \t\tShow the class and the users that were on it\r\n"
			sTmp = sTmp.."+viewschedule \t\t\tShow the class that the nick is in\r\n"
			sTmp = sTmp.."\r\n\tOnly for Ops\r\n"
			sTmp = sTmp.."+delclass  \t\tDeletes the class\r\n"
			user:SendPM(sBot, sTmp)
			return 1
		elseif (cmd == "+addclass") then
			local s,e,class,schd,wday = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s+(%S+)")
			if (class == nil or schd == nil or wday == nil) then
				user:SendPM(sBot, "Syntax Error, +addclass   , you must write a class name, schedule and week days (m, tu, w, thu, f or sat).")
			else
				AddClass(user, class, schd, wday)
				user:SendPM(sBot, "Done.")
			end
			return 1
		elseif (cmd == "+viewclasses") then
			OpenAllClass(user)
			return 1
		elseif (cmd == "+viewclass") then
			local s,e,class,wday = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
			if (class == nil or wday == nil) then
				user:SendPM(sBot, "Syntax Error, +viewclass  , you must write a class name and week days (m, tu, w, thu, f or sat).")
			else
				ViewClass(user, class, wday)
			end
			return 1
		elseif (cmd == "+delclass" and user.bOperator) then
			local s,e,class,wday = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
			if (class == nil or wday == nil) then
				user:SendPM(sBot, "Syntax Error, +delclass  , you must write a class name and week days (m, tu, w, thu, f or sat).")
			else
				DeleteClass(user, class, wday)
			end
			return 1
		elseif (cmd == "+viewschedule") then
			local s,e,usr = strfind(data, "%b<>%s+%S+%s+(%S+)")
			if (usr == nil) then
				user:SendPM(sBot, "Syntax Error, +viewschedule , you must write a nick.")
			else
				ViewUser(user, usr)
			end
			return 1
		end
	end
end

function AddClass(user, class, schedule, wday)
	local sLine = ""
	local time = 0
	local myclass = strlower(user.sName)..".dat"
	local cl = strlower(class)..strlower(wday)
	cl = cl..".dat"

	-------------Add To Class.dat-------------
	if (readfrom(cl) == nil) then
		sLine = sLine.."sche= "..schedule.." "..wday.."\r\n"
		writeto(cl)
		write(sLine)
		writeto()
		sLine = ""
	else
		readfrom(cl)
		while 1 do
			local line = read()
			if (line == nil) then
				if (time == 0) then
					sLine = sLine..user.sName
					readfrom()
					writeto(cl)
					write(sLine)
					writeto()
					sLine = ""
					time = 0

					-------------Add To User.dat-------------
					if (readfrom(myclass) == nil) then
						writeto(myclass)
						write(class.." "..wday.." @ "..schedule)
						writeto()
					else
						readfrom(myclass)
						while 1 do
							local line = read()
							if (line == nil) then
								sLine = sLine..class.." "..wday.." @ "..schedule
								break
							else
								sLine = sLine..line.."\r\n"
							end
						end
						readfrom()
						writeto(myclass)
						write(sLine)
						writeto()
						sLine = ""
					end
				end
				break
			else
				local s,e,nickname = strfind(line, "(%S+)")
				if (strlower(user.sName) == strlower(nickname) and nickname ~= "sche=") then
					time = 1
				end
				sLine = sLine..line.."\r\n"
			end
		end
	end

	-------------Add To AllClass.dat-------------
	if (readfrom(allclass) == nil) then
		writeto(allclass)
		write(class.." "..wday.." "..schedule.." 0")
		writeto()
	else
		readfrom(allclass)
		while 1 do
			local line = read()
			if (line == nil) then
				if (time == 0) then
					sLine = sLine..class.." "..wday.." "..schedule.." 0"
				end
				break
			else
				local s,e,clss,weekd,schd,number = strfind(line, "(%S+)%s+(%S+)%s+(%S+)%s+(%S+)")
				if (strlower(clss) == strlower(class) and strlower(weekd) == strlower(wday)) then
					number = tonumber(number) + 1
					sLine = sLine..clss.." "..weekd.." "..schd.." "..number.."\r\n"
					time = 1
				else
					sLine = sLine..line.."\r\n"
				end
			end
		end
		readfrom()
		writeto(allclass)
		write(sLine)
		writeto()
		sLine = ""
		time = 0
	end
end

function OpenAllClass(user)
	local sLine = ""
	if (readfrom(allclass) == nil) then
		sLine = "There is no Class in the file AllClass.dat."
	else
		sLine = sLine.."### All Class ###\r\n\r\n"
		readfrom(allclass)
		while 1 do
			local line = read()
			if (line == nil) then
				break
			else
				local s,e,clss,weekd,schd,number = strfind(line, "(%S+)%s+(%S+)%s+(%S+)%s+(%S+)")
				if (clss ~= nil and schd ~= nil and number ~= nil) then
					sLine = sLine..clss.." @ "..schd.." "..weekd.." ("..number.." Students)\r\n"
				end
			end
		end
		readfrom()
	end
	user:SendPM(sBot, sLine)
end

function ViewClass(user, class, wday)
	local sLine = ""
	local cl = strlower(class)..strlower(wday)
	cl = cl..".dat"
	if (readfrom(cl) == nil) then
		sLine = "That Class does not exist."
	else
		readfrom(cl)
		while 1 do
			local line = read()
			if (line == nil) then
				break
			else
				local s,e,usr = strfind(line, "(%S+)")
				if (usr ~= nil) then
					if (usr == "sche=") then
						local s,e,schd,weekd = strfind(line, "%S+%s+(%S+)%s+(%S+)")
						sLine = sLine.."### "..class.." @ "..schd.." "..weekd.." ###\r\n\r\n"
					else
						sLine = sLine..usr.."\r\n"
					end
				end
			end
		end
		readfrom()
	end
	user:SendPM(sBot, sLine)
end

function ViewUser(user, usr)
	local sLine = ""
	local myclass = strlower(usr)..".dat"
	if (readfrom(myclass) == nil) then
		sLine = "That User does not exist."
	else
		sLine = sLine.."### User Schedule ###\r\n\r\n"
		readfrom(myclass)
		while 1 do
			local line = read()
			if (line == nil) then
				break
			else
				sLine = sLine..line.."\r\n"
			end
		end
		readfrom()
	end
	user:SendPM(sBot, sLine)
end

function DeleteClass(user, class, wday)
	local sLine = ""
	local cl = strlower(class)..strlower(wday)
	cl = cl..".dat"
	if (readfrom(cl) == nil) then
		sLine = "That Class does not exist."
	else
		readfrom()
		remove(cl)
		if (readfrom(allclass) == nil) then
			sLine = "There is no Class in the file AllClass.dat."
		else
			readfrom(allclass)
			while 1 do
				local line = read()
				if (line == nil) then
					break
				else	
					local s,e,clss,weekd = strfind(line, "(%S+)%s+(%S+)")
					if (strlower(clss) ~= strlower(class) and strlower(weekd) ~= strlower(wday)) then
						sLine = sLine..line.."\r\n"
					end
				end
			end
		end
		readfrom()
		writeto(allclass)
		write(sLine)
		writeto()
		sLine = "That Class has been removed."
	end
	user:SendPM(sBot, sLine)
end

Best regards, nErBoS
--## nErBoS Spot ##--

SMF spam blocked by CleanTalk