summary refs log tree commit diff stats
path: root/infinite.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-08-15 18:45:29 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-08-15 18:45:29 -0400
commit0baed246b6f287e1c03519536011f34e87d19920 (patch)
treed9eb44f28d8ad5edf7e78f47e3bdb830114a7432 /infinite.cpp
parentd7fbb904d0dc70d1eada1dbb5f57f2ee9e5b399f (diff)
downloadinfinite-0baed246b6f287e1c03519536011f34e87d19920.tar.gz
infinite-0baed246b6f287e1c03519536011f34e87d19920.tar.bz2
infinite-0baed246b6f287e1c03519536011f34e87d19920.zip
Started to modernize bot (this is completely broken) modern
Diffstat (limited to 'infinite.cpp')
-rw-r--r--infinite.cpp83
1 files changed, 44 insertions, 39 deletions
diff --git a/infinite.cpp b/infinite.cpp index 37c4d72..1bf5c8e 100644 --- a/infinite.cpp +++ b/infinite.cpp
@@ -432,38 +432,36 @@ class fill_blanks {
432 } 432 }
433}; 433};
434 434
435int main(int argc, char** argv) 435infinite::infinite(
436 std::string configFile,
437 std::mt19937& rng) :
438 rng_(rng)
436{ 439{
437 srand(time(NULL)); 440 // Load the config file.
438 rand(); rand(); rand(); rand(); 441 YAML::Node config = YAML::LoadFile(configFile);
439
440 Magick::InitializeMagick(nullptr);
441
442 if (argc != 2)
443 {
444 std::cout << "usage: infinite [configfile]" << std::endl;
445 return -1;
446 }
447
448 std::string configfile(argv[1]);
449 YAML::Node config = YAML::LoadFile(configfile);
450 442
443 // Set up the Twitter client.
451 twitter::auth auth; 444 twitter::auth auth;
452 auth.setConsumerKey(config["consumer_key"].as<std::string>()); 445 auth.setConsumerKey(config["consumer_key"].as<std::string>());
453 auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); 446 auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
454 auth.setAccessKey(config["access_key"].as<std::string>()); 447 auth.setAccessKey(config["access_key"].as<std::string>());
455 auth.setAccessSecret(config["access_secret"].as<std::string>()); 448 auth.setAccessSecret(config["access_secret"].as<std::string>());
456 449
457 twitter::client client(auth); 450 client_ = std::unique_ptr<twitter::client>(new twitter::client(auth));
451
452 // Set up the verbly database.
453 database_ = std::unique_ptr<verbly::database>(
454 new verbly::database(config["verbly_datafile"].as<std::string>()));
455
456 // Set up the sentence generator.
457 generator_ = std::unique_ptr<sentence>(new sentence(*database_, rng_));
458 458
459 // Parse forms file 459 // Parse forms file
460 std::map<std::string, std::vector<std::string>> groups;
461 { 460 {
462 std::ifstream datafile(config["forms_file"].as<std::string>()); 461 std::ifstream datafile(config["forms_file"].as<std::string>());
463 if (!datafile.is_open()) 462 if (!datafile.is_open())
464 { 463 {
465 std::cout << "Could not find forms file" << std::endl; 464 throw std::invalid_argument("Could not find forms file");
466 return 1;
467 } 465 }
468 466
469 bool newgroup = true; 467 bool newgroup = true;
@@ -485,7 +483,7 @@ int main(int argc, char** argv)
485 { 483 {
486 newgroup = true; 484 newgroup = true;
487 } else { 485 } else {
488 groups[curgroup].push_back(line); 486 groups_[curgroup].push_back(line);
489 } 487 }
490 } 488 }
491 } 489 }
@@ -493,32 +491,37 @@ int main(int argc, char** argv)
493 491
494 // Read in fonts 492 // Read in fonts
495 std::string fontsdirname = config["fonts"].as<std::string>(); 493 std::string fontsdirname = config["fonts"].as<std::string>();
496 std::vector<std::string> fonts; 494 DIR* fontdir;
495 struct dirent* ent;
496
497 if ((fontdir = opendir(fontsdirname.c_str())) == nullptr)
497 { 498 {
498 DIR* fontdir; 499 throw std::invalid_argument("Couldn't find fonts");
499 struct dirent* ent; 500 }
500 if ((fontdir = opendir(fontsdirname.c_str())) == nullptr)
501 {
502 std::cout << "Couldn't find fonts." << std::endl;
503 return -1;
504 }
505 501
506 while ((ent = readdir(fontdir)) != nullptr) 502 while ((ent = readdir(fontdir)) != nullptr)
503 {
504 std::string dname(ent->d_name);
505 if ((dname.find(".otf") != std::string::npos)
506 || (dname.find(".ttf") != std::string::npos))
507 { 507 {
508 std::string dname(ent->d_name); 508 fonts_.push_back(dname);
509 if ((dname.find(".otf") != std::string::npos) || (dname.find(".ttf") != std::string::npos))
510 {
511 fonts.push_back(dname);
512 }
513 } 509 }
514
515 closedir(fontdir);
516 } 510 }
517 511
512 closedir(fontdir);
513
518 std::string colorsfile(config["colors"].as<std::string>()); 514 std::string colorsfile(config["colors"].as<std::string>());
519 515
520 verbly::data database {config["verbly_datafile"].as<std::string>()};
521 516
517
518}
519
520int main(int argc, char** argv)
521{
522
523
524
522 for (;;) 525 for (;;)
523 { 526 {
524 // Generate the text 527 // Generate the text
@@ -776,12 +779,14 @@ int main(int argc, char** argv)
776 779
777 textimage.annotate(towrite, Magick::CenterGravity); 780 textimage.annotate(towrite, Magick::CenterGravity);
778 textimage.opacity(((double)MaxRGB) * 0.8); 781 textimage.opacity(((double)MaxRGB) * 0.8);
779 image.composite(textimage, 0, 0, Magick::OverCompositeOp); 782 //image.composite(textimage, 0, 0, Magick::OverCompositeOp);
780 783
781 image.magick("jpg"); 784 image.magick("png");
782 785
783 Magick::Blob outputimg; 786 Magick::Blob outputimg;
784 image.write(&outputimg); 787 //image.write(&outputimg);
788 image.write("output.png");
789 return 1;
785 790
786 std::cout << "Generated image!" << std::endl << "Tweeting..." << std::endl; 791 std::cout << "Generated image!" << std::endl << "Tweeting..." << std::endl;
787 792