Advertisement
Guest User

D Hugbot

a guest
Dec 30th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.50 KB | None | 0 0
  1. // A simple hug bot in D.
  2. // @author RainbowDashDC
  3. // @version 1.1A
  4. // Shoutout too @suhosinpony who got me into D.
  5.  
  6. // Import needed libs.
  7. import std.stdio;
  8. import std.datetime;
  9. import std.getopt;
  10.  
  11. ulong get_time() {
  12.     // Return Current Time.
  13.     return Clock.currTime().toUnixTime();
  14. }
  15.  
  16. void start_timer(string message, int timer) {
  17.     // Declare variables and base init them.
  18.     ulong time_now = get_time();
  19.     ulong time_until = time_now+(timer);
  20.    
  21.     while(time_until != time_now) {
  22.         time_now = get_time();
  23.     }
  24.     writeln(message);
  25. }
  26.  
  27.  
  28. int main(string[] args) {
  29.     // Init Values
  30.     ulong time = get_time();
  31.     string message = "*hugs*";
  32.     int timer = 60*60;
  33.     bool help;
  34.    
  35.     // Get CMD Args
  36.     getopt(
  37.      args,
  38.      "message", &message,
  39.      "timer", &timer,
  40.      "help", &help
  41.     );
  42.    
  43.     // Check for help
  44.     if(help) {
  45.         writeln("(C)2013-Present RDashINC");
  46.         writeln("Version 1.1A, GNUGPLv3");
  47.         writeln("\nSYNOPSIS: hb [OPTIONS]...");
  48.         writeln("DESC: Print out [message] each [timer].");
  49.         writeln("\nOPTIONS:");
  50.         writeln("   --help           Show this page.");
  51.         writeln("   --mesage=[msg]   Use this instead of '*hugs*'");
  52.         writeln("   --timer=[second] Use this for timer.");
  53.         writeln("\nEmail bug reports and suggestions too <allardj64@gmail.com>");
  54.         return 0;
  55.     }
  56.    
  57.     // Get initial time.
  58.     writeln("Started: ", time);
  59.    
  60.     // Write Settings.
  61.     writeln("Using '", message, "' as the message.");
  62.     writeln("Operating at '", timer, "' timer");
  63.     while(true) {
  64.         start_timer(message, timer);
  65.     }
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement