小赖子的英国生活和资讯

Discord 机器人 steemit 上线了!

阅读 桌面完整版

昨天弄了个 crytocurrency 机器人, 今天五分钟封装一下PHP代码, 上线了 steemit 机器人.

通过 ?steem_id 这样的格式来查询 steemit 帐号的信息. 效果如下:

discord-bot

我们中文区有属于自己的 discord 频道, 通过链接: https://discord.gg/7ctT3Xt 即可加入.
添加discord steem机器人到你的 discord server 里:

https://discordapp.com/api/oauth2/authorize?client_id=418196534660694037&permissions=522304&scope=bot

BUG提交给我: @justyy
机器人 24 /7 在线, 但不排除偶尔不在线上维护更新开发等 .

PHP Discord SteemIt 机器人源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
ini_set('memory_limit', '200M');
include __DIR__.'/vendor/autoload.php';
require('valid.php');
 
use Discord\Discord;
 
$discord = new Discord([
  'token' => 'YOUR-TOKEN'
]);
 
$discord->on('ready', function ($discord) { 
  $discord->on('message', function ($message, $discord) {
    $msg = trim($message->content);
    $cmd = strtolower($msg);
    if (strlen($msg) <= 3) {
      return;
    }
    if ($msg[0] != '?') {
      return;
    }
    $user = trim(substr($msg, 1));
    if (isValidId($user)) {
      $url =  "https://uploadbeta.com/api/steemit/account/profile/?id=$user";                        
      $data = json_decode(file_get_contents($url), true);
      $price_usd = 4;
      $url2 = "https://api.coinmarketcap.com/v1/ticker/steem-dollars/";
      $data2 = json_decode(file_get_contents($url2), true);
      if ($data2) {
        $price_usd = $data2[0]['price_usd'];
      }
      if ($data) {
        $s = '@' . $user . "\n";
        $s .= '    Reputation: ' . $data['rep'] . "\n";
        $a = round($data['esp']['vesting_sp'], 3);
        $b = round($data['esp']['received_sp'], 3);
        $c = round($data['esp']['delegated_sp'], 3);
        $s .= '    Effective Steem Power: ' . round($data['esp']['esp'],2) ."\n";
        $s .= '    Steem Power: ' . $a ;
        $s .= ' +' . $b ." ";
        $s .= '-' . $c ." \n";
        $s .= '    Voting Power: ' . round($data['vp'], 3) . "%\n";
        $s .= '    Last Voted Time: ' . str_replace('T'," ",$data['last_vote_time']) . "\n";                          
        $s .= '    STEEM: ' . round($data['steem'], 3) . "\n";
        $s .= '    SBD: ' . round($data['sbd'], 3) . "\n";
        $s .= '    Account Value: $' . round($data['value'] * $price_usd, 2) . "\n";
        $s .= '    Account Age: ' . round($data['online']) . " Days\n";
        $message->channel->sendMessage($s);                           
      }         
    }    
  });
});
 
$discord->run();
<?php
ini_set('memory_limit', '200M');
include __DIR__.'/vendor/autoload.php';
require('valid.php');

use Discord\Discord;

$discord = new Discord([
  'token' => 'YOUR-TOKEN'
]);

$discord->on('ready', function ($discord) {	
  $discord->on('message', function ($message, $discord) {
    $msg = trim($message->content);
    $cmd = strtolower($msg);
    if (strlen($msg) <= 3) {
      return;
    }
    if ($msg[0] != '?') {
      return;
    }
    $user = trim(substr($msg, 1));
    if (isValidId($user)) {
      $url =  "https://uploadbeta.com/api/steemit/account/profile/?id=$user";                        
      $data = json_decode(file_get_contents($url), true);
      $price_usd = 4;
      $url2 = "https://api.coinmarketcap.com/v1/ticker/steem-dollars/";
      $data2 = json_decode(file_get_contents($url2), true);
      if ($data2) {
        $price_usd = $data2[0]['price_usd'];
      }
      if ($data) {
        $s = '@' . $user . "\n";
        $s .= '    Reputation: ' . $data['rep'] . "\n";
        $a = round($data['esp']['vesting_sp'], 3);
        $b = round($data['esp']['received_sp'], 3);
        $c = round($data['esp']['delegated_sp'], 3);
        $s .= '    Effective Steem Power: ' . round($data['esp']['esp'],2) ."\n";
        $s .= '    Steem Power: ' . $a ;
        $s .= ' +' . $b ." ";
        $s .= '-' . $c ." \n";
        $s .= '    Voting Power: ' . round($data['vp'], 3) . "%\n";
        $s .= '    Last Voted Time: ' . str_replace('T'," ",$data['last_vote_time']) . "\n";                          
        $s .= '    STEEM: ' . round($data['steem'], 3) . "\n";
        $s .= '    SBD: ' . round($data['sbd'], 3) . "\n";
        $s .= '    Account Value: $' . round($data['value'] * $price_usd, 2) . "\n";
        $s .= '    Account Age: ' . round($data['online']) . " Days\n";
        $message->channel->sendMessage($s);                           
      }         
    }    
  });
});

$discord->run();

Discord 欢迎机器人 – PHP 源码

更新, 稍微加了几行代码, 就把 Discord 的欢迎机器人一起绑定到了 steemit 机器人上了.

discord-welcome-bot

每次当有人加到 Discord 里, 这个机器人就会显示欢迎信息. 代码如下:

1
2
3
4
5
  $discord->on('GUILD_MEMBER_ADD', function ($member, $discord) { 
    $newUserId = $member->user->id; 
    $guild = $discord->guilds->first(); 
    $guild->channels->get("name", "general")->sendMessage("Welcome/欢迎 <@" . $newUserId . "> !");
  });
  $discord->on('GUILD_MEMBER_ADD', function ($member, $discord) { 
    $newUserId = $member->user->id; 
    $guild = $discord->guilds->first(); 
    $guild->channels->get("name", "general")->sendMessage("Welcome/欢迎 <@" . $newUserId . "> !");
  });

英文: The SteemIt Discord Bot with PHP Source Code

强烈推荐

微信公众号: 小赖子的英国生活和资讯 JustYYUK

阅读 桌面完整版
Exit mobile version