yatbcpp  0.0.1
Yet another Telegram Bot CPP Library
Token.cc
Go to the documentation of this file.
1 //
2 // Created by norbert on 12.08.17.
3 //
4 
5 #include <cstring>
6 #include <fstream>
7 #include <iostream>
9 
10 #include "inc/bot/Token.h"
11 //Namespace for Library
12 using namespace yatbcpp;
13 using namespace std;
15 // TODOS: EXCEPTIONS AND STUFF
16 // Token is only 0-45 long _> 46
18 
23 const std::string Token::getToken() const {
24  string s = token;
25  return s;
26 }
27 
32 void Token::setToken(string s){
33  if(s.size()<=0){
34  //Token May not be less or zero
35  }
36  if(s.size()>=__TELEGRAM_TOKEN_LENGTH){
37  //Token too big
38  }
39  token = s;
40 }
41 
47  this->setToken(ttoken);
48 }
49 
50 Token::Token(const Token& T) {
51  token=T.token;
52 }
53 
54 
60 Token Token::FromFile(const char *filelocation) {
61 // char token[__TELEGRAM_TOKEN_LENGTH];
62  std::string token;
63  ifstream file (filelocation, ios::in);
64  if(file.is_open()){
65 // int readTokens=0;
66 // for(readTokens=0;readTokens<__TELEGRAM_TOKEN_LENGTH;readTokens++){
67 // file.get(token[readTokens]);
68 // }
69  std::getline(file,token);
70 // if(readTokens!=__TELEGRAM_TOKEN_LENGTH){
71  if(token.size()!=__TELEGRAM_TOKEN_LENGTH){
72  std::cerr << "Telegram Token Size Missmatch::" << token.size() << " instead of " << __TELEGRAM_TOKEN_LENGTH << std::endl;
73  //An Error has occured, we did not stop where we thougt to stop
74  }
75  file.close();
76  }
77  else {
78  throw file_not_found("Supplied File Location does not contain a file");
79  }
80  return Token(token.c_str());//sigh hoffentlich frisst das nich speicher
81 
82 }
#define __TELEGRAM_TOKEN_LENGTH
Definition: Token.h:11
static Token FromFile(const char *fileLocation)
Definition: Token.cc:60
Definition: Bot.h:27
void setToken(std::string s)
Definition: Token.cc:32
Token(const char ttoken[__TELEGRAM_TOKEN_LENGTH])
Definition: Token.cc:46
std::string token
Definition: Token.h:29
const std::string getToken() const
Definition: Token.cc:23