05-30-2020, 08:17 +0200
AuthorPost
Turbo  06-18-2007, 00:02   MSN  Homepage
Moderator
Member since 06/2007
5 Posts
Location: Netherlands
  1. Author: Björn 'Turbo' B. 
  2.                  
  3. Copyright © 2009 Turbo-Dev.org - All Rights Reserved.
#
  1. Version/Date check list.
#    1.0 - June 18 2007
#    1.1 - December 22 2009
#    1.2 - Januari 21 2010

namespace eval ::request_system {

    # - Config

    ## Set here the trigger you wanna use.
    variable reqtrigger "."

    ## Please leave this.
    variable reqversion "1.2"

    ## Set here the channel (where users can use the request command).
    variable reqchannel "#choose-your-channel"

    ## Set here the channel where all msgs report goes to.
    variable reportchannel "#choose-your-channel"

    ## Set here the require users that a requested channel needs.
    variable require "25"

    # - File Check

    if {![file exists request]} { file mkdir request }

    # - Binds

    bind pub -|- ${reqtrigger}request [namespace current]::start
    bind pub m|m ${reqtrigger}suspend [namespace current]::suspend
    bind pub m|m ${reqtrigger}unsuspend [namespace current]::unsuspend
    bind pub m|m ${reqtrigger}info [namespace current]::suspended
    bind pub m|m ${reqtrigger}remove [namespace current]::removebot
    bind need -|- * [namespace current]::need:check

    # - End Of Bindings

    # - End Of Config

    ## Don`t touch anything below this (only if you know what you are doing)


    proc start {nick host hand chan text} {
        global request
        variable reqchannel
        variable reportchannel
        variable require
        set requestchannel [lindex [split $text] 0]
        if {$reqchannel == "" || $reportchannel == "" || $require == ""} {
            putlog "(Request) Please check your Configuration."
            return 0
        } elseif {![string equal -nocase $chan "$reqchannel"]} {
            putserv "PRIVMSG $chan :(Request) You can only request on channel: $reqchannel"
            return 0
        } elseif {[info exists request(proceeding)]} {
            putserv "PRIVMSG $chan :(Request) There is already a request proceeding, please wait and try again."
            return 0       
        } elseif {$requestchannel == ""} {
            putserv "PRIVMSG $chan :(Request) $::lastbind <#channel>"
            return 0
        } elseif {[string index $requestchannel 0] != "#"} {
            putserv "PRIVMSG $chan :(Request) ($requestchannel) is no such channel name."
            return 0
        } elseif {[string tolower $requestchannel] == "[string tolower $reqchannel]"} {
            putserv "PRIVMSG $chan :(Request) ($requestchannel) is no request channel."
            return 0
        } elseif {[issuspended $requestchannel] == "1"} {
            putserv "PRIVMSG $chan :(Request) ($requestchannel) has been suspended."
            return 0
        } elseif {[validchan $requestchannel] == "1"} {
            putserv "PRIVMSG $chan :(Request) Already on channel: ($requestchannel)"
            return 0
        } else {
            putquick "PRIVMSG $reportchannel :(Request) Status: Proceeding - Channel: $requestchannel - Nickname: $nick"
            channel add $requestchannel
            set request(proceeding) "1"
            set request(chan) "$requestchannel"
            set request(nick) "$nick"
            set request(required) "$require"
        }
        bind raw - 315 [namespace current]::end
        proc end {from key text} {
            global request
            variable reportchannel
            if {![info exists request(proceeding)]} { return }
            set users "[llength [chanlist $request(chan)]]"
            if {$users < "$request(required)"} {
                channel remove $request(chan)
                set request(reason) "Not enough users."
                putquick "privmsg $request(nick) :(Request) Failed: Not enough users on $request(chan) you need $request(required) users, and currently have $users"
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
            } elseif {![onchan $request(nick) $request(chan)]} {
                channel remove $request(chan)
                set request(reason) "User not channel."
                putquick "privmsg $request(nick) :(Request) Failed: Didn`t found you on $request(chan)"
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
            } elseif {![isop $request(nick) $request(chan)]} {
                channel remove $request(chan)
                set request(reason) "User not opped on channel."
                putquick "privmsg $request(nick) :(Request) Failed: You don`t have op on $request(chan)"
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
            } elseif {![onchan Q $request(chan)]} {
                channel remove $request(chan)
                set request(reason) "Q not on channel"
                putquick "privmsg $request(nick) :(Request) Failed: Didn`t found Q on $request(chan)"
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
            } else {
                putquick "PRIVMSG $request(nick) :(Request) $request(nick) Your request is accepted, to remove me from $request(chan) you can ask bot owner: $::owner"
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: Yes"
                channel remove $request(chan)
            }
            unset request(chan)
            unset request(nick)
            unset request(required)
            unset request(proceeding)
            unbind raw - 315 [namespace current]::end
        }
    }

    proc issuspended {chan} {
        if {![file exists request/suspended.txt]} { return 0 }
        set file [open request/suspended.txt "r+"]
        set found 0
        while {![eof $file]} {
            set info [gets $file]
            if {[string equal -nocase "[lindex [split $info] 0]" $chan]} { set found "1" }
        }
        close $file
        if {$found == "1"} {
            return 1
        } else {
            return 0
        }
    }

    proc removebot {nick host hand chan text} {
        variable reqchannel
        variable reportchannel
        set removechannel [lindex [split $text] 0]
        if {[string equal -nocase $removechannel "$reqchannel"]} {
            putserv "PRIVMSG $chan :(Request) ($removechannel) not allowed."
            return 0
        } elseif {$removechannel == ""} {
            putserv "PRIVMSG $chan :(Request) $::lastbind <#channel>"
            return 0
        } elseif {[validchan $removechannel] == "0"} {
            putserv "PRIVMSG $chan :(Request) ($removechannel) is not a valid channel."
            return 0           
        } else {
            channel remove $removechannel
            putquick "PRIVMSG $reportchannel :(Request) Removed channel: $removechannel."
        }
    }

    proc need:check {chan type} {
        global request
        variable reportchannel
        if {![info exists request(proceeding)]} { return }
        if {![string equal -nocase $chan "$request(chan)"]} { return }
        switch -exact -- [string tolower [lindex [split $type] 0]] {
            "unban" {
                channel remove $request(chan)
                set request(reason) "Couldn`t check the channel because i found myself banned."
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
                unset request(chan)
                unset request(nick)
                unset request(required)
                unset request(proceeding)
            }
            "invite" {
                channel remove $request(chan)
                set request(reason) "Couldn`t check the channel because the channel is set to +i (invite only)."
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
                unset request(chan)
                unset request(nick)
                unset request(required)
                unset request(proceeding)
            }
            "limit" {
                channel remove $request(chan)
                set request(reason) "Couldn`t check the channel because the channel is set to +l (limit)."
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
                unset request(chan)
                unset request(nick)
                unset request(required)
                unset request(proceeding)
            }
            "key" {
                channel remove $request(chan)
                set request(reason) "Couldn`t check the channel because the channel is set to +k (key)."
                putquick "PRIVMSG $reportchannel :(Request) Channel: $request(chan) - Nickname: $request(nick) - Accepted: No - Reason: $request(reason)"
                unset request(reason)
                unset request(chan)
                unset request(nick)
                unset request(required)
                unset request(proceeding)
            }
        }
        unbind raw - 315 [namespace current]::end
    }

    proc suspend {nick host hand chan text} {
        if {![file exists request/suspended.txt]} { set file [open request/suspended.txt w+]; close $file }
        if {[lindex [split $text] 0] == "" || [join [lrange [split $text] 1 end]] == "" || [string index [lindex [split $text] 0] 0] != "#"} {
            putquick "PRIVMSG $chan :(Request) $::lastbind <#channel> <reason>"
        } else {
            set file [open request/suspended.txt "r+"]
            set found 0
            set suspendchan [lindex [split $text] 0]
            set suspendreason [join [lrange [split $text] 1 end]]
            while {![eof $file]} {
                set info [gets $file]
                if {[string equal -nocase "[lindex [split $info] 0]" $suspendchan]} { incr found 1 }
            }
            if {$found != "0"} {
                putquick "PRIVMSG $chan :(Request) Already suspended."
            } else {
                puts $file "$suspendchan $nick [strftime {%m/%d/%y}] $suspendreason"
                putquick "PRIVMSG $chan :(Request) Suspended."
            }
            close $file
        }
    }
    proc unsuspend {nick host hand chan text} {
        if {![file exists request/suspended.txt]} {
            putquick "PRIVMSG $chan :(Request) Couldn`t find the suspended channels list."
        } elseif {[lindex [split $text] 0] == "" || [string index [lindex [split $text] 0] 0] != "#"} {
            putquick "PRIVMSG $chan :(Request) $::lastbind <#channel>"
        } else {
            set file [open request/suspended.txt "r"]
            set found 0
            set list {}
            set suspendchan [lindex [split $text] 0]
            while {![eof $file]} {
                set info [gets $file]
                if {[eof $file]} { break }
                if {[string equal -nocase "[lindex [split $info] 0]" $suspendchan]} {
                    incr found 1
                } else {
                lappend list [join [split $info]] }
            }
            close $file
            if {$found == "0"} {
                putquick "PRIVMSG $chan :(Request) $suspendchan is not suspended."
            } else {
                set file [open request/suspended.txt "w+"]
                foreach {info} $list {
                puts $file $info }
                close $file
                putquick "PRIVMSG $chan :(Request) $suspendchan has been removed from suspended list."
            }
        }
    }       
    proc suspended {nick host hand chan text} {
        if {![file exists request/suspended.txt]} {
            putquick "PRIVMSG $chan :(Request) Couldn`t find the suspended channels list."
        } elseif {[lindex [split $text] 0] == "" || [string index [lindex [split $text] 0] 0] != "#"} {
            putquick "PRIVMSG $chan :(Request) $::lastbind <#channel>"
        } else {
            set file [open request/suspended.txt r]
            set buffer [split [read $file] \n]
            set suspendchan [lindex [split $text] 0]
            foreach info $buffer {
                if {[string equal -nocase "[lindex [split $info] 0]" $suspendchan]} {
                    putquick "PRIVMSG $chan :(Request) \'[lindex [split $info] 0]\' has been suspended by ([lindex [split $info] 1]) on [lindex [split $info] 2] with reason: [join [lrange [split $info] 3 end]]"
                    return
                }
            }
            putquick "PRIVMSG $chan :(Request) No info found about $suspendchan, not suspended."
            close $file
        }
    }

}

putlog "Request System ${request_system::reqversion} Is Scripted By 'Björn 'Turbo' B.'"
This post was edited 1 times, last on 02-02-2010, 01:16 by Turbo
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen | Time: 164.5 msec, CPU time: 66.6 msec, 30 Database queries in 116.1 msec | 5 kB (31.9 kB) | Timezone: +0200