AtoolforcreatingbotsforMastodonwhichreadRSS/Atomfeeds.
Features:
MultiplebotsfromonescriptMultiplefeedsperbotSupports(valid)RSSandAtomStateless:inthesensethatitdoesnotmaintainacacheofwhichRSSpostshavebeenconvertedtotoots.CurrentlyrunningtheRFIBotonmastodon.social
SetupRequiresPHP7.0
YouwillneedacertfiletorunGuzzle.
Youwillalsoneedtosetthetimezoneofyourcomputerviathephp.inidate.timezonesetting.
LoadDependenciesDependenciesareloadedviaComposer
composerinstallItusesthefollowingdependencies:
phediverse/mastodon-restdg/rss-phpguzzlehttp/guzzleApplicationThiscodetakescareofrunningthe3rdpartyapplicationwhichhandlesthebots.
Youwillneedtocopy/configurations/APP.example.jsonto/configurations/APP.json.
In/configurations/APP.jsonchangethenamepropertytoacustomname.
BotConfigurationYouwillfirstneedtomanuallymaketheaccountontheMastodoninstanceofyourchoicewithanemail,passwordandusername.
Thefile/configurations/example.jsonisanexampleofabotconfiguration.CreateanewJSONinthe/configurations/folderandnameitforyourbot.
{"instance":"social.targaryen.house",//like'mastodon.social'"username":"my_username",//usernameforyourbot'saccount,notdisplayname//notusedatthispoint"email":"myemail+botname@mail.com",//emailforyourbot'slogin"password":"realpassword",//passwordforyourbot'slogin"hashtags":["all"],//arrayofstringsthatyouwantas//hashtags(#)ineachtoot//donotadd'#'"feeds":[{//arrayoffeedsforthisbot"type":"rss",//typeoffeed,rssoratom"url":"https://www.website.com/rss/one.xml",//urltofeed"hashtags":["cats"]//hashtagsforeverytootfromthisfeed},{"type":"rss","url":"https://www.website.com/rss/two.xml","hashtags":["music"]},{"type":"atom","url":"https://www.website.com/atom/three.xml","hashtags":["mood"]}]}Createaseparateconfigurationfileforeachbotyouwishtorun.
UseUpdatesIfyourconfigurationfileiscalledmy_rss.json,thentheRSSitemscanbeposted/updatedwith:
php/path/to/php-mastodon-rss-to-bot-stateless/index.phpmy_rssPleasenotethelackof'.json'intheparameter.
Tokeeptheapplication'stateless'(seetop),thetoolworksbasedoffoftimestamps.ThetoolwillcheckthetimestampofthelatesttootandgetallFeeditemsafterthattimestampandpoststhem.
Obviously,thishasthepotentialtonotbeasaccurateasabotwithacache,butI'mtoolazytobuildone.Ifyourfeedhasitemsaddedeveryminute(hopefullyunlikely),thenthistoolmaymissanitemortwoalongtheway.
Ifthebotisnewandhasnoposts,itwillonlypostthemostrecentfeeditem,nottheentirefeed.
SchedulingInordertohaveabotthatupdatesregularly,youwillneedtoscheduletheabovePHPcallwithaCrontaskoraScheduledTaskdependingonyoursystem.
Youwillneedtoscheduleseparatetasksforeachbot/config.
AdditionalIfyouneedtodisablethetoolforawhile(systemmaintenance,etc),butyoudon'twantthebottofloodMastodonwithabunchofbelatedpostswhenitstartsupagain,youcanjustmakeapostdirectlytothebotviatheMastodoninterfaceandthenstartthescheduledtaskagain.ThenewpostwillmakesurethemostrecenttimestampintheToottimelineisuptodate.
TODOCreateconfigclasstovalidateconfigurationsAddutilityclassandPHPUnitforlongtermstabilityGettootlengthbyinstanceReplacestrlenwithmorereliablefunctionExtendtoanyiterable,fetchable,timestampedresource
评论