Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. ;; This is a very simple example on how to use the API
  2. on *:text:!ingame*:#: {
  3. ;; Check if something is entered
  4. if ($2 == $null) { msg $chan No ingame entered! }
  5. else {
  6. ;; Save channel & requested info
  7. set %stats.chan $chan
  8. set %stats.info $2
  9. ;; Open the socket to the API page
  10. sockopen -e stats d-bot.net 443
  11. }
  12. }
  13. on *:sockopen:stats: {
  14. ;; Enter API key, the desired version, sort of requested information and as last the information itself
  15. sockwrite -nt $sockname GET /api/api.php?key=16fdddrz9etcw&version=com&sort=ingame&info= $+ %stats.info HTTP/1.0
  16. sockwrite -nt $sockname Host: d-bot.net
  17. sockwrite -nt $sockname $crlf
  18. }
  19. on *:sockread:stats: {
  20. ;; Read out all the information and save it into the variable %r.
  21. sockread %stats.output
  22. if ($chr(124) isin %stats.output) {
  23. tokenize 124 %stats.output
  24. set %r. [ $+ [ $1 ] ] $2-
  25. }
  26. if (ERROR isin %stats.output) {
  27. msg %stats.chan ERROR %r.error
  28. unset %stats.*
  29. unset %r.*
  30. sockclose stats
  31. }
  32. ;; All the information has been received and saved, now let's read it!
  33. if (Copyright [D-BoT] isin %stats.output) {
  34. ;; Some basic if and then's to make it more readable (Use the copyright somewhere in a msg)
  35. msg %stats.chan Ingame %r.ingame Rank %r.rank (https://d-bot.net)
  36. msg %stats.chan Has been online for %r.ontime ( $+ %r.on_per $+ )
  37. if (%r.gender == female) { set %pronoun her }
  38. else { set %pronoun his }
  39. msg %stats.chan And is on position %r.rp based on %pronoun rankprogress
  40. if (%r.status != death) { msg %stats.chan Which is position %r.rp_alive of all alive players }
  41.  
  42. ;; Everything done now, forget all the information and close the socket
  43. unset %stats.*
  44. unset %r.*
  45. sockclose stats
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement