BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => AO 0.6.x Custom/Unofficial modules => Anarchy Online Archive => AO official modules => Topic started by: Zarkingu on December 13, 2005, 09:41:46 pm

Title: Modified News.php
Post by: Zarkingu on December 13, 2005, 09:41:46 pm
Modified Blondengy's News.php with a !headline command.

Modified News.php (http://www.dmgincweb.com/bebot_files/News.phps)

Probably not very good programming, still just a beginner with PHP  ;D
It works whough  :)
Title: Re: Modified News.php
Post by: Naturalistic on December 13, 2005, 11:00:42 pm
Going to be doing a big change to the !news function, I'll post it once I finish :)

Lack of control of news items sucks :P
Title: Re: Modified News.php
Post by: Khalem on December 14, 2005, 01:16:42 am
Going to be doing a big change to the !news function, I'll post it once I finish :)

Lack of control of news items sucks :P

Amen. Hence why its a big item on my Todo list :P
I'll hold of on my plans until youve posted yours Naturalistic.
I can however mention the very basic changes i had in mind from current 0.2.x:
- ID field should be just that, a unique ID. Its possible, but not probable that two news items be added at the same time. For interoperability and standards sake, id's should be autoincrement integer values starting at 1. (A convert function should take the old timestamp based ID's and enter new id's starting from 1, and timestamps should be their own field)
- Admins/Superadmins should be able to delete any news item, and posters should be allowed to delete their own posts.
- The ability to sticky news items (integer 0/1 field in database)
- The ability to configure the number of sticky newsitems to display aswell as the number of newsitems to be displayed.
- Admins should have the ability to list any number of news items for.. err.. administrative purposes. Ie a !news show x   where x is an integer value.
- Potentially merge the Raids module into the News module as they are basically the same, only with a different name. Again, probably integer 0/1 field in database.
Title: Re: Modified News.php
Post by: Xenixa on December 18, 2005, 02:28:44 pm
Well I got board and did pretty much what you were looking at doing with the News module Khalem.

This version combines the Original News and Raids Modules by Foxferal, also includes updates/ideas by Naturalistic and Zarkingu.
Additional Database Fields added/changed:
 ID renamed to TIME, ID added to Auto Inc starting at 1
 TYPE field to Denote News Type I.E.: 1 = News, 2 = Headline, 3 = Raid News

Notes on Headline: I've written this one to were you can only have one Headline in the News Table at any given time. If a new headline is given it delete's the old one before it inserts the new one. The first time you do !news and no Headline is present it'll just show "No Headline's" at the top of the Info window.

xen.afraid.org/bebot_files/news.php (ftp://xen.afraid.org/bebot_files/news.php)

Giver a once over and lemme know what ya think.

EDIT: There is a commented ALTER TABLE statement included in the file above that will update the current News Table. Oh and either rename or remove Raids.php before using this. I still have yet to write a script to move entries from the Raids news table to the News table. Actually I did it by hand by performing the same ALTER TABLE script using the appropriet table name then exported the table to a .sql file and changing the INSERT INTO to news rather than raids before loading the sql file.
Title: Re: Modified News.php
Post by: Khalem on December 18, 2005, 07:23:29 pm
Ohh nice.

I'll have a look at this one as soon as im done with the server move hell im in.
Title: Re: Modified News.php
Post by: Akarah on December 19, 2005, 07:22:15 am
the news i had already came with
Code: [Select]
  $db -> query("CREATE TABLE IF NOT EXISTS news
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
              name VARCHAR(30),
              news TEXT,
        time INT NOT NULL)");

so using your update command fails because time already exists..

i think all that is needed in my case was

Code: [Select]
mysql> ALTER TABLE news, ADD COLUMN type INT DEFAULT '2' NULL  after id;

it worked at least :)
Title: Re: Modified News.php
Post by: Akarah on December 19, 2005, 09:23:23 am
now that i think about it some more, setting the new column to type 1 might be more appropriate, since there can only be one headline... yea? :)

so either do the above line then:

Code: [Select]
mysql> UPDATE news SET type = 1 WHERE type = 2;

or just set the default to 1, assuming that doesn't break the script (i haven't looked closely)
Title: Re: Modified News.php
Post by: Xenixa on December 19, 2005, 10:02:49 am
Well what I was doing to make sure only 1 Headline entry exists is to have it remove any Type 2 entry before Setting the new one.

I.E. in the function set_headline
Code: [Select]
$this -> bot -> db -> query("DELETE FROM news WHERE type = '2'");
$this -> bot -> db -> query("INSERT INTO news (type, time, name, news) VALUES ('2' ," . time() .
  ", '" . $name . "', '" . addslashes($msg) . "')");

Seems to work pretty well as I havn't seen more than 1 Headline appear after changing it a couple times to test it.
Title: Re: Modified News.php
Post by: Akarah on December 19, 2005, 10:08:08 am
i was just noting that when adding the new column, if you had previous news entries (i had about 10 or so) they would all get set to type 2, thus get deleted apparently ;p

Title: Re: Modified News.php
Post by: Xenixa on December 19, 2005, 12:41:10 pm
OOOh ok I see what your saying, ya set default to 1, guess I should have updated that ALTER TABLE a bit more before stuffing it there. Originally I was gunna set Headlines to 1 and News to 2 but some how ended up going the other way around.
Title: Re: Modified News.php
Post by: Xenixa on December 19, 2005, 03:33:36 pm
OOOOPS!!! I found a mistake in the copy I had on my ftp server.

Using !raids calls up Regular News and not Raid News. -- FIXED (copy on ftp server updated)
Title: Re: Modified News.php
Post by: Khalem on December 25, 2005, 02:28:51 pm
Im going to make some minor changes to your module Xenixa and add it to SVN :)
Title: Re: Modified News.php
Post by: Khalem on January 31, 2006, 10:18:46 pm
Heres my modified version.
- Slimmed it down a little bit
- Added last modified date to show in initial return line
- Added clicklinks for delete
- Allow multiple headlines to be added and also deleted. Currently set to display 3 headline items.
- More sane permission checks on deleting entries.

On a side note, there has to be a better way to treat the result from the MySQL query when you know there is only going to be one return, but i havent found one yet.

http://svn.shadow-realm.org:7100/svn/BeBot/trunk/modules/News.php
Title: Re: Modified News.php
Post by: Xenixa on February 02, 2006, 02:08:43 am
OOoh!! I like it, I been meaning to add those items myself. Well the click links and last updated bit in the reply. :)
I like the security updates also. I have to admit I didn't really put much thought into updating that.

Oh and some syntax errors in this posted version.
Line 163 - Missing an additional Quote before semi-colon. Corrected:>  $inside .= "<font color=CCInfoText>" . $val[3] . "";
Line 168 - 1 too many quotes. Corrected:>  $inside .= "\n\n";
Title: Re: Modified News.php
Post by: Khalem on February 02, 2006, 01:23:49 pm
Syntax errors was already fixed in SVN. Posting direct link instead :)

Some of the things im still planning to do:
- The number of items to show for news and possibly headlines should be configurable, but the settings table still needs a revamp
- x last raid entries shown in !news as with headline(s)
- The ability to "clicklink" convert a headline into ordinary news, and with this feature it might not be neccecary to be able to limit the number of headlines shown. Headlines afterall do become irrelevant with time and become "just news" anyways.
- Find a better way to pull a single result without doing the foreach loop.
- Move the command handler into a separate function to eliminate code duplication for each handler.
Title: Re: Modified News.php
Post by: Alreadythere on February 02, 2006, 02:03:41 pm
- Find a better way to pull a single result without doing the foreach loop.
I guess you are talking about code like
Code: [Select]
$result = $this -> bot -> db -> select("SELECT id, time  FROM news WHERE type = '2' OR type = '1' ORDER BY id DESC LIMIT 0, 1");
if (!empty($result))
foreach ($result as $val)
{
$newsdate = gmdate("dS M, H:i", $val[1]);
}

Just try
Code: [Select]
$result = $this -> bot -> db -> select("SELECT id, time  FROM news WHERE type = '2' OR type = '1' ORDER BY id DESC LIMIT 0, 1");
if (!empty($result))
$newsdate = gmdate("dS M, H:i", $result[0][1]);
$result is an array, $result[0] is the first entry - which has to exist, otherwise it would be empty. And you know that there won't be a second entry anyways.
Title: Re: Modified News.php
Post by: Aesgaard on February 28, 2007, 02:32:20 am
Is it just me or is all the host servers down ?
Title: Re: Modified News.php
Post by: jjones666 on February 28, 2007, 08:21:09 am
The latest version of !news should be in Bebot 0.2.11.  For a good alternative search for NewNews on the forum (by Glarawyn).

-jj-
Title: Re: Modified News.php
Post by: Aesgaard on September 02, 2007, 02:07:10 pm
News for version 0.4 would be nice *sigh* :P
Title: Re: Modified News.php
Post by: Joulette on November 25, 2007, 06:01:02 pm
In the news module, there's unfortunately no way to delete a headline item if it breaks the gui, which is what happened to our new today. I added a headline item that broke the gui. Now I don't have a way to delete it, and we can't view the news either.

Any suggestions?

thanks
Title: Re: Modified News.php
Post by: Blueeagle on November 26, 2007, 07:52:46 am
Best way would be to not use html-ish tags in the items. Those should ofcourse have been converted to &lt; and &gt; before being inserted.

For now deleting them from the database manually using either the command line or some administrator tool would be best.
SimplePortal 2.3.7 © 2008-2024, SimplePortal