<h1>Connect Evennia to Twitter<aclass="headerlink"href="#connect-evennia-to-twitter"title="Permalink to this headline">¶</a></h1>
<p><aclass="reference external"href="https://en.wikipedia.org/wiki/twitter">Twitter</a> is an online social networking service that enables users to send and read short messages called “tweets”. Following is a short tutorial explaining how to enable users to send tweets from inside Evennia.</p>
<p>You must first have a Twitter account. Log in and register an App at the <aclass="reference external"href="https://apps.twitter.com/">Twitter Dev Site</a>. Make sure you enable access to “write” tweets!</p>
<p>To tweet from Evennia you will need both the “API Token” and the “API secret” strings as well as the “Access Token” and “Access Secret” strings.</p>
<p>Twitter changed their requirements to require a Mobile number on the Twitter account to register new apps with write access. If you’re unable to do this, please see <aclass="reference external"href="https://dev.twitter.com/notifications/new-apps-registration">this Dev post</a> which describes how to get around it.</p>
<h3>A basic tweet command<aclass="headerlink"href="#a-basic-tweet-command"title="Permalink to this headline">¶</a></h3>
<p>Evennia doesn’t have a <codeclass="docutils literal notranslate"><spanclass="pre">tweet</span></code> command out of the box so you need to write your own little <aclass="reference internal"href="../Components/Commands.html"><spanclass="doc std std-doc">Command</span></a> in order to tweet. If you are unsure about how commands work and how to add them, it can be an idea to go through the <aclass="reference internal"href="../Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-Adding-Commands.html"><spanclass="doc std std-doc">Adding a Command Tutorial</span></a> before continuing.</p>
<p>You can create the command in a separate command module (something like <codeclass="docutils literal notranslate"><spanclass="pre">mygame/commands/tweet.py</span></code>) or together with your other custom commands, as you prefer.
This is how it can look:</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in mygame/commands.tweet.py, for example</span>
<spanclass="n">caller</span><spanclass="o">.</span><spanclass="n">msg</span><spanclass="p">(</span><spanclass="sa">f</span><spanclass="s2">"Your tweet was </span><spanclass="si">{</span><spanclass="n">tlen</span><spanclass="si">}</span><spanclass="s2"> chars long (max 280)."</span><spanclass="p">)</span>
<p>We default to limiting tweet access to players with <codeclass="docutils literal notranslate"><spanclass="pre">Developers</span></code>-level access <em>or</em> to those players that have the permission “tweet”</p>
<p>To allow allow individual characters to tweet, set the <codeclass="docutils literal notranslate"><spanclass="pre">tweet</span></code> permission with</p>
<p>You may change the <aclass="reference internal"href="../Components/Locks.html"><spanclass="doc std std-doc">lock</span></a> as you feel is appropriate. Change the overall permission to <codeclass="docutils literal notranslate"><spanclass="pre">Players</span></code> if you want everyone to be able to tweet.</p>
<p>Now add this command to your default command set (e.g in <codeclass="docutils literal notranslate"><spanclass="pre">mygame/commands/defalt_cmdsets.py</span></code>) and <codeclass="docutils literal notranslate"><spanclass="pre">reload</span></code> the server. From now on those with access can simply use <codeclass="docutils literal notranslate"><spanclass="pre">tweet</span><spanclass="pre"><message></span></code> to see the tweet posted from the game’s Twitter account.</p>
<p>Rather than using an explicit command you can set up a Script to send automatic tweets, for example to post updated game stats. See the <aclass="reference internal"href="../Howtos/Web-Tweeting-Game-Stats.html"><spanclass="doc std std-doc">Tweeting Game Stats tutorial</span></a> for help.</p>