• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Bot - Creating new Threads?

#1
I need to add some Threads wich not generated by Users.
Is there an easy way without being modify SQL Tables?
We currently have an Bot wich posts Threads in vB over SQL. We need this on xenforo ;)

Hope anybody can help me ;)

greets Kevin
 
R

ragtek

Guest
#2
I've coded a little helper for me.
Everybody is allowed to use it if he wants^^
PHP:
class Ragtek_Helper_DataWriter
{
    /**
     * Helper for XenForo Thread Datawriter to create a thread
     * @param array $user
     * @param <int> $forumId
     * @param <str> $subject
     * @param <str> $message
     * @return <array> Thread Information
     */
    static public function createThread($user, $forumId, $subject, $message)
    {
        $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
        $writer->set('user_id', $user['user_id']);
        $writer->set('username', $user['username']);
        $writer->set('title', $subject);
            $postWriter = $writer->getFirstMessageDw();
            $postWriter->set('message', $message);
        $writer->set('node_id', $forumId);
        $writer->preSave();
        $writer->save();
        return $writer->getMergedData();
    }
You can see it here in action http://xenforo.com/community/threads/ragtek-contact-thread.5521/