This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

[Request] Assistance Notifying System - King

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
K
King
Voice
Posts: 5
Joined: Thu Feb 04, 2016 7:12 am
Location: America

[Request] Assistance Notifying System - King

Post by King »

Hello world!

This script is very simple and easy to use, this would be classified as a helper for support channels. This script is used to notify users listed on a .txt file whenever someone is in need of help, let me explain further below.

Whenever someone joins the channel they'll be given a notice about how to request help, shown in the script below. Once someone type !assist in the channel, the bot will PRIVMSG all the users on the assist list saying someone needs assistance on that channel, which shows their nickname and userhost.

Example:

Joins: King (King@userhost.example) joins #channel

[notice from Bot] Welcome to the IRC support channel King!
[notice from Bot] If you need assistance, type !assist

<~King> !assist
[notice from Bot] Thanks for your corperation King! Your request was sent, please wait for at least 5-15 minutes for a response!

A private messag from the bot to the users on the list would show

<Bot> King (King@userhost.example) has requested for your assistance on #channel

See how simple it is? Now I need help making the list a bit dynamic, if I add a user, and they changed nick, the bot still pm's the nick, or if the user isn't online. So I need the script to pm online users listed on the list along with if they've changed nickname.

I've consider using handles, but then perhaps the users would need to be logged on to the bot and get a global flag, reason why I didn't do it this way is because I want to be able to !add or !remove users from the list instantly, without having them registering for a handle or requires each handle to be logged in and create a password.

The best way is by a file which stores listed users and get the bot to check each names on the file to see if they're on the channel or if any host matches the specified name on the list, whichever is preferred..

Here's my working code, this is the code I have now, as I've already explained earlier about.

Code: Select all

# Assistance Script v0.4

# Binds 
bind pub - !alist assistant:list 
bind pub - !auser assistant:adduser 
bind pub - !duser assistant:deluser
bind pub - !assist assistant:help
bind join - * assistant:greet

# This is where the file is located and stored as $ulist
set ulist "scripts/assistlist.txt"


# This proc greets each user who joins the channel with the following notices.
proc assistant:greet {nick userhost handle chan} {
	
	puthelp	"NOTICE $nick :Welcome to the IRC Support channel $nick!"
	puthelp "NOTICE $nick :If you need assistance, type !assist"
}

# This proc is used to view all users on the list after adding them.
# Each users on this list is saved to a text document known as assistlist.txt
# The variable is set as $ulist, once a user type !ulist in the channel they'll see 
# all the users who's added to the list.
proc assistant:list {nick userhost handle chan text} {
	global ulist 
	
	# checks if user is not op or not owner
	if {!([isop $nick $chan] || [ishalfop $nick $chan] || [isvoice $nick $chan] || [matchattr $handle +n])} {
		putserv "NOTICE $nick :You're not authorized to use this command."
		putcmdlog "ASSIST INFO: Unauthorized access to !alist by $nick."
		return 0
	}
	# opening the file for read only and set data to read $fp
	set fp [open $ulist "r"] 
	set data [read -nonewline $fp] 
	close $fp 
	
	# set the variable lines to split the data
	# then sort the names in alphabetical order on the list of names.
	set lines [split $data "\n"] 
	set line_sort [lsort -dictionary $lines]
	
	# Separate names using a , Example: John, Brown, Paul, Michael
	set lines1 [join $line_sort ", "]
	
	# Notices the user who's on the list. Example: Assistants: John, Brown, Paul, Michael
	putserv "NOTICE $nick :\002Assistants:\002 $lines1"
	putcmdlog "ASSIST INFO: Assistants was viewed by $nick."
	return 0
}

# Adding users to the list of names 
proc assistant:adduser {nick userhost handle chan text} {
	global ulist 
	
	# Check if the user is not op or owner.
	if {!([isop $nick $chan] || [matchattr $handle +n])} {
		putserv "NOTICE $nick :You're not authorized to perform this command."
		putcmdlog "ASSIST INFO: Unauthorized access to !auser by $nick."
		return 0
	}
	if {$text == ""} { 
		putserv "NOTICE $nick :Usage: !auser <nickname>"
		putcmdlog "ASSIST INFO: Usage info was sent to $nick."
		return 0 
	}  
	# Sets the "Line_to_add" as the user input after !auser $text
	set line_to_add $text
	set lines_space [join $line_to_add " "]
	set fname $ulist 
	set fp [open $fname "a"] 
	puts $fp $lines_space 
	close $fp 
	
	# Notices the user that the name was added to the list
	putquick "NOTICE $nick :$text was added to the Assist List."
	putcmdlog "ASSIST INFO: $nick added $text to the Assist List."
} 
}


# This proc is to remove a user from the list
proc assistant:deluser {nick userhost handle chan text} {
	global ulist 
	
	# Check if the user is not op or owner.
	if {!([isop $nick $chan] || [matchattr $handle +n])} {
		putserv "NOTICE $nick :You're not authorized to perform this command."
		putcmdlog "ASSIST INFO: Unauthorized access to !duser by $nick."
		return 0
	}
	if {$text == ""} { 
		putserv "NOTICE $nick :Usage: !duser <nickname>"
		putcmdlog "ASSIST INFO: Assist usage was sent to $nick."
		return 0 
	}
	set fp [open $ulist "r"] 
	set data [read -nonewline $fp] 
	close $fp 
	
	set lines [split $data "\n"] 
	
	set el_num [lsearch $lines $text] 
	
	if {$el_num != -1} { 
		
		set lines [lreplace $lines $el_num $el_num] 
	} 
	
	puthelp "NOTICE $nick :$text was removed from the Assist List."
	putcmdlog "ASSIST INFO: $nick removed $text from the Assist List." 
	
	set fp [open $ulist "w"] 
	
	foreach element $lines { 
		puts $fp $element 
	} 
	close $fp 
}

# Notifying users on the assist list by pm. Once someone type !assist, this proc is triggered.
proc assistant:help {nick userhost handle chan text} {
	
	global ulist 
	
	set fp [open $ulist "r"] 
	set data [read -nonewline $fp] 
	close $fp 
	
	# Splits the data into a list
	set lines [split $data "\n"] 
	
	# Arrange the letters alphabetically
	set line_sort [lsort -dictionary $lines] 
	
	# Adds a space between names, previous was: Nick1Nick2Nick3Nick3, now it's Nick1 Nick2 Nick3 Nick4
	set lines1 [join $line_to_add " "]
	
	# Split the names from $line1 and place them in a variable $names
	foreach names [split $lines1] {
		if {[onchan $names $chan]} {
			# Check if each names on the list is online on the channel then PRIVMSG them. 
			putserv "PRIVMSG $names :\002$nick\002 \00314($userhost)\003 has requested for your assistance on \002$chan\002"
		}
	}
	# Notice the $nick which has issued the !assist command.
	putserv "NOTICE $nick :Thanks for your cooperation \002$nick!\002 Your \037request\037 was sent, please wait for at least 5-15 minutes for a response!"
	putcmdlog "ASSIST INFO: $nick ($userhost) requested for assistance on $chan"
}
putlog "Assistance Script by Kyle (King) has loaded."
The To-Do-List

You can create a completely different script similar to this with what's needed below.

These are already performed by the script.

* Once a user types !assist on the channel, the bot will then PMs all the users on the database all at once.

* The PM is "King (King@userhost.example) has requested for your assistance on #channel" This is the user's info which has triggered the !assist command on the channel.

* The script already consist of a channel flag which was removed, no need to create another channel enable and disable script

* You're able to add and remove users on the list with 2 commands, !auser and !duser.

* The script only PMs online users who's on the list.

* You're able to view all the users on the list with !alist

These are things that's not on the script but needed.

* Be able to view all online user on the list.

* Be able to use one command for adding and removing users, for example: !assistant add <nickname> & !assistant del <nickname>

* Be able to create a spam protection for each specific user who has triggered the !assist command, for example: If a user has triggered the command, he/she won't be able to use it for the next 5-15 minutes. While others can use it, same procedure for each users.

Note: These below are NOT IMPORTANT!

* Users should be able to type !assist or type !assist <reason> which will send each assistants on the list the PM with the reason added.

* Be able to use a command to view the last 5 users who has previously requested for assistance with the !assist command and the time.
Example:
Last 5 Previous Requests:
User: King (King@userhost.example) Time: 3 hours and 27 minutes ago.
User: John (Blake@unaffiliated/John) Time: 3 days and 53 minutes ago.
...

* Be able to view all available commands, if possible, show specific commands to only authorized users, else show available commands to all users.
Best Regards,
- King
Post Reply