messageboard script request
 

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

messageboard script request

Started by bokkepoot, 09 October, 2004, 03:03:01

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bokkepoot

Hello everyone

A few months ago I asked to you all very genius programming people for a script for a messageboard in LUA ofcourse.

I was that time very happy that in 4 hours time a script was placed here. In a first look it works very perfect. I'm running now a few days and have discovered some problems.

First of all I would place the whole (little added) script here, so you all know about what I'm talking:

--## Post Bot
--## Requested by Bokkepoot
--## Made by nErBoS
--## Commands:
--##   For All users:
--##      -add       - Will create a post for all
--##      -read      - Read all HUB Post (if OP it will also show the OPs posts)
--##
--##   For OPs only:
--##      -opadd       - Will create a post only to OPs
--##      +delpost    - Will delete a type of post (all = for users post, ops = op posts) with his ID number


sBot = "messageboard"

arrPost = {
   ["all"] = {},
   ["ops"] = {},
}
fPost = "post.dat"

--## Configuration ##--

uLaterPtokax = 1   -- Choose 0 if you are using Ptokax version 0.3.3.0 or higher
         -- Choose 1 if you are using Ptokax version lower then 0.3.3.0

--## END ##--

function Main()
   frmHub:RegBot(sBot)
   LoadFromFile(fPost)
end

function OnExit()
   SaveToFile(fPost , arrPost , "arrPost")
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 == "-add") then
         local s,e,post = strfind(data, "%b<>%s+%S+%s+(.+)")
         if (post == nil) then
            user:SendPM(sBot, "Syntax Error, -add , you must write a message.")
         else
            local pos = GetPosition(arrPost.all)
            arrPost.all[pos] = {}
            arrPost.all[pos]["post"] = post
            arrPost.all[pos]["by"] = user.sName
            arrPost.all[pos]["date"] = GetTime()
            SendToAll(sBot, "A new post is posted on the user-messageboard. Type -read to read it")
            user:SendPM(sBot, "The post was been add with success.")
            if (uLaterPtokax == 1) then
               OnExit()
            end
         end
         return 1
      elseif (cmd == "-opadd" and user.bOperator) then
         local s,e,post = strfind(data, "%b<>%s+%S+%s+(.+)")
         if (post == nil) then
            user:SendPM(sBot, "Syntax Error, -opadd , you must write a message.")
         else
            local pos = GetPosition(arrPost.ops)
            arrPost.ops[pos] = {}
            arrPost.ops[pos]["post"] = post
            arrPost.ops[pos]["by"] = user.sName
            arrPost.ops[pos]["date"] = GetTime()
            user:SendPM(sBot, "The post was been add with success.")
            if (uLaterPtokax == 1) then
               OnExit()
            end
         end
         return 1
      elseif (cmd == "+delpost" and user.bOperator) then
         local s,e,type,id = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
         if (type == nil or id == nil) then
            user:SendPM(sBot, "Syntax Error, +delpost , you must write a type and a ID of the post.")
         elseif (tonumber(id) == nil) then
            user:SendPM(sBot, "Syntax Error, +delpost , the ID of the post must be a number.")
         elseif (strlower(type) ~= "all" and strlower(type) ~= "ops") then
            user:SendPM(sBot, "Syntax Error, +delpost , the type must be all or ops.")
         elseif (arrPost[strlower(type)][tonumber(id)] == nil) then
            user:SendPM(sBot, "The isn't any Post with the ID "..id)
         else
            arrPost[strlower(type)][tonumber(id)] = nil
            user:SendPM(sBot, "The Post was been erased.")
            if (uLaterPtokax == 1) then
               OnExit()
            end
         end
         return 1
      elseif (cmd == "-read") then
         local sTmp,pos,table = "The Post of the HUB:\r\n\r\n"
         for pos, table in arrPost.all do
            sTmp = sTmp.."ID Number: "..pos.."\r\n"
            sTmp = sTmp.."Posted by: "..table.by.."\r\n"
            sTmp = sTmp.."Posted at: "..table.date.."\r\n"
            sTmp = sTmp.."\t --## POST ##-- \r\n"
            sTmp = sTmp..table.post.."\r\n"
            sTmp = sTmp.."\t --## END ##-- \r\n\r\n"
         end
         if (user.bOperator) then
            sTmp = sTmp.."The OPs Post of the HUB:\r\n\r\n"
            for pos, table in arrPost.ops do
               sTmp = sTmp.."ID Number: "..pos.."\r\n"
               sTmp = sTmp.."Posted by: "..table.by.."\r\n"
               sTmp = sTmp.."Posted at: "..table.date.."\r\n"
               sTmp = sTmp.."\t --## POST ##-- \r\n"
               sTmp = sTmp..table.post.."\r\n"
               sTmp = sTmp.."\t --## END ##-- \r\n\r\n"
            end
         end
         user:SendPM(sBot, sTmp)
         return 1
      end
   end
end

function GetPosition(table)
   local pos = 0
   while 1 do
      SendToAll(sBot, pos)
      if (table[pos] == nil) then
         return pos
      else
         pos = pos + 1
      end
   end
end

function GetTime()
   s = date("%S")
   h = date("%H")
   m = date("%M")
   d = date("%d")
   mm = date("%m")
   y = date("%y")
   Date = "Day: "..d.."/"..mm.."/20"..y.." Hour: "..h..":"..m..":"..s
   return Date
end

function Serialize(tTable, sTableName, sTab)
   assert(tTable, "tTable equals nil");
   assert(sTableName, "sTableName equals nil");

   assert(type(tTable) == "table", "tTable must be a table!");
   assert(type(sTableName) == "string", "sTableName must be a string!");

   sTab = sTab or "";
   sTmp = ""

   sTmp = sTmp..sTab..sTableName.." = {\n"

   for key, value in tTable do
      local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

      if(type(value) == "table") then
         sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
      else
         local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
         sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
      end

      sTmp = sTmp..",\n"
   end

   sTmp = sTmp..sTab.."}"
   return sTmp
end

function SaveToFile(file , table , tablename)
   writeto(file)
   write(Serialize(table, tablename))
   writeto()
end

function LoadFromFile(file)
   if (readfrom(file) ~= nil) then
      readfrom(file)
      dostring(read("*all"))
      readfrom()
   end
end

THIS IS THE END

Thanks to nErBoS for creating the original script.

I have tested and there are a few problems:

1) when users (also operators for their board) place a message, their will come a message in the Mainchat of the hub like this:

     [02:06] 0
     [02:06] 1
     [02:06] 2
     [02:06] 3
     [02:06] 4
     [02:06] 5
     [02:06] 6
     [02:06] 7
     [02:06] 8
     [02:06] 9
     [02:06] A new post is posted on  
     the user-messageboard. Type -read to read it

Is it possible to remove these anoying messageboard messages in the mainchat ?

2) I must give in a new message in the mainchat (by using -add or -opadd). Is it possible to change the script, so I can send first a private message to the bot and type only there these messages ?

3) after placing a new message on the messageboard, is it possible to send a message to the mainchat with the following info: "user "XXXXXX" has placed a message on the messageboard". Messages placed by operators (using the function -opadd) on the messageboard must be send to the mainchat and only published to operators there.

4) after placing a message on the messageboard, is it possible (in case for user and operator) to see in the private message to the bot the following message: "Your message is placed correctly"

5) is it possible to change the script so messages older that xxxxx days will be deleted automatic ?




I hope somebody can help me with the script. I'm sure it can be helpfull for a lot of other people who are running a hub.

Greetings


Bokkepoot

bokkepoot

here is the messageboard script (only user messageboard) which is developt for the Neo-Modus DC hub, maybe you can do something with it:

'Bulletin Script 1.0 by Gadget
'If script wont work, check out that you installed hub software using proper installer
'and that your antivirus software is not blocking scripts which try to access files.
Dim sBotName,sFileName,iExpireTime,aModerators,bUsersCanAdd,bOpOnly,iMinLenght,iMaxLenght,iInterval,sEntries,iCount,sLast,sAdder,iTicker

Sub Main()
sBotName = "01 USERS-Messageboard" '<- The bot's name.
sFileName = "01 USERS-Messageboard.txt" '<- Filename where entries will be saved.
iExpireTime = 30 '<- Expiration of added messages in days.
aModerators = Array("Admin") '<- List of moderators who can remove entries sent by other users or clear all entries.
bUsersCanAdd = True '<- True if you want users be able to add messages to Bulletin, False if only ops can.
bOpOnly = False '<- True if operators only can use the Bulletin, False if it's for all users.
iMinLenght = 5 '<- Minimum lenght of message in characters.
iMaxLenght = 90000 '<- Maximum lenght of message in characters.
iInterval = 0 '<- Minimum interval in minutes how often users can add new messages.

sEntries=DelOld(ReadFile(sFileName))
sAdder=""
frmHub.RegisterBotName cStr(sBotName)
iTicker=0
tmrScriptTimer.Interval=60000
tmrScriptTimer.Enabled=True
End Sub

Sub DataArival(curUser,sCurData)
If Left(sCurData,1)="<" Or Left(sCurData,Len(sBotName)+6)="$To: "+sBotName+" " Then
sCmd=Mid(sCurData,InStr(sCurData,">")+2)
sText=""
If InStr(sCmd," ") Then
sText=Mid(sCmd,InStr(sCmd," ")+1)
sCmd=Left(sCmd,InStr(sCmd," ")-1)
End If
sReply=""
Select Case LCase(sCmd)
Case "-read"
If (Not curUser.bOperator And Not bIsModerator(curUser.sName)) And bOpOnly Then
sReply="This bulletin is for operators and moderators only."
Else
If iCount>0 Then
sReply="Welcome to Bulletin. There are "+CStr(iCount)+" messages:"+vbCrLf+vbCrLf+Parse(sEntries)
sReply=sReply+vbCrLf+vbCrLf+"Report unwanted messages to some of the moderators: "+Join(aModerators,", ")
Else
sReply="There are no messages in Bulletin."
End If
If bUsersCanAdd Or curUser.bOperator Or bIsModerator(curUser.sName) Then
If bIsModerator(curUser.sName) Then
sReply=sReply+vbCrLf+"You can add messages with '-add ', remove messages with '-remove ' and remove all messages with '-removeall'."
Else
sReply=sReply+vbCrLf+"You can add messages with '-add ' and remove your messages with '-remove '."
End If
End If
End If
Case "-add"
If sAdder=curUser.sName Then
sReply="You just added a message. Please wait "+CStr(iInterval)+" minutes and try again."
ElseIf Not curUser.bOperator And Not bIsModerator(curUser.sName) And (bOpOnly Or Not bUsersCanAdd) Then
sReply="Only operators or moderators can add messages to Bulletin."
ElseIf Len(sText)sReply="Your message was not added because it is too short."
ElseIf Len(sText)>iMaxLenght Then
sReply="Your message was not added because it is too long."
ElseIf InStr(sText,"[Added ") Then
sReply="Do not try to fake messages!"
Else
sAdder=curUser.sName
sEntries=DelOld(sEntries+vbCrLf+Replace(sText,vbCrLf,"\n")+"|"+curUser.sName+"|"+CStr(Now()))
Call WriteFile(sFileName,sEntries)
sReply="Your message is now added."
If bOpOnly Then
For each user in colUsers
If user.bOperator Or bIsModerator(curUser.sName) Then user.SendData CStr("<"+sBotName+"> "+curUser.sName+" just added new message. Type '-read' in main chat or privately to "+sBotName+" to read it.")
Next
Else
colUsers.SendChatToAll CStr(sBotName),CStr(curUser.sName+" just added new message. Type '-read' in main chat or privately to "+sBotName+" to read it.")
End If
End If
Case "-remove"
If Not curUser.bOperator And Not bIsModerator(curUser.sName) And (bOpOnly Or Not bUsersCanAdd) Then
sReply="Only operators or moderators can remove messages from Bulletin."
ElseIf sText="" Then
sReply="Specify beginning of text or date of message you want to remove."
Else
aEntries=Split(sEntries,vbCrLf)
For i=0 To UBound(aEntries)
aEntry=Split(aEntries(i),"|")
If UBound(aEntry)=2 Then
If LCase(sText)=LCase(Left(aEntry(0),Len(sText))) or LCase(sText)=LCase(Left(aEntry(2),Len(sText))) Then
If LCase(curUser.sName)=LCase(aEntry(1)) Or bIsModerator(curUser.sName) Then
sReply="Following message was removed:"+vbCrLf+Parse(aEntries(i))
aEntries(i)=""
sEntries=DelOld(Join(aEntries,vbCrLf))
Call WriteFile(sFileName,sEntries)
Exit For
Else
sReply="Only moderators can remove messages sent by other users!"
End If
End If
End If
Next
If sReply="" Then sReply="Couldn't find that message."
End If
Case "-removeall"
If Not bIsModerator(curUser.sName) Then
sReply="Only moderators can remove all messages."
Else
sEntries=DelOld("")
Call WriteFile(sFileName,sEntries)
sReply="All messages have been removed."
End If
End Select
If sReply<>"" Then
If Left(sCurData,1)="<" Then
curUser.SendData CStr("<"+sBotName+"> "+sReply)
Else
curUser.PrivateMessage CStr(sBotName),cStr(sReply)
End If
End If
End If
End Sub

Sub NewUserConnected(curUser)
If curUser.bOperator Or bIsModerator(curUser.sName) Or Not bOpOnly Then
If iCount>0 Then
curUser.SendData CStr("<"+sBotName+"> There are "+CStr(iCount)+" messages in Bulletin, last was added "+sLast+". Type '-read' in main chat or privately to "+sBotName+" to read messages.")
Else
curUser.SendData CStr("<"+sBotName+"> There are no messages in Bulletin. Type '-read' in main chat or privately to "+sBotName+" to get instructions how to add messages.")
End If
End If
End Sub

Sub OPConnected(curUser)
Call NewUserConnected(curUser)
End Sub

Sub tmrScriptTimer_Timer()
iTicker=iTicker+1
If iTicker=>iInterval Then
iTicker=0
sAdder=""
End If
End Sub

Function ReadFile(sFileName)
On Error Resume Next
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(sFileName) Then
Set file=fso.OpenTextFile(sFileName,1,True)
ReadFile=file.ReadAll
file.Close
Else
ReadFile="Welcome to Gadget's Bulletin!|"+sBotName+"|"+CStr(Now())
End If
End Function

Sub WriteFile(sFileName,sText)
Set fso=CreateObject("Scripting.FileSystemObject")
Set file=fso.CreateTextFile(sFileName,True)
file.Write(CStr(sText))
file.Close
End Sub

Function DelOld(sText)
DelOld=""
aEntries=Split(sText,vbCrLf)
iCount=0
For i=0 To UBound(aEntries)
aEntry=Split(aEntries(i),"|")
If UBound(aEntry)=2 Then
If DateDiff("d",aEntry(2),Now())If DelOld="" Then
DelOld=Join(aEntry,"|")
Else
DelOld=DelOld+vbCrLf+Join(aEntry,"|")
End If
iCount=iCount+1
sLast=aEntry(2)
End If
End If
Next
End Function

Function Parse(sText)
Parse=""
aEntries=Split(sText,vbCrLf)
iCount=0
For i=0 To UBound(aEntries)
aEntry=Split(aEntries(i),"|")
If UBound(aEntry)=2 Then
If DateDiff("d",aEntry(2),Now())If Parse="" Then
Parse=aEntry(0)+" [Added by "+aEntry(1)+" in "+aEntry(2)+"]"
Else
Parse=Parse+vbCrLf+aEntry(0)+" [Added by "+aEntry(1)+" in "+aEntry(2)+"]"
End If
iCount=iCount+1
sLast=aEntry(2)
End If
End If
Next
Parse=Replace(Parse,"\n",vbCrLf)
End Function

Function bIsModerator(sUser)
bIsModerator=False
For i=0 to UBound(aModerators)
If LCase(CStr(sUser))=LCase(CStr(aModerators(i))) Then bIsModerator=True
Next
End Function




I hope that I'm asking not too much for you all, but please give it a try. Every help is welcome


greetings


Bokkepoot

chub

you'd have to translate that entire script to LUA since it's in vb-script.

Psycho_Chihuahua

and about your first script posted


of course it shows "" seeing thats the name of the Bot.

If you dont want it to show the bots n?me then you would have to change a couple of things in the script
as like

SendPM becomes SendToAll
frmHub:RegBot(sBot)  falls away

and a coup?e of other small things...
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

SMF spam blocked by CleanTalk