├── CHANGELOG.md ├── lib ├── modules │ ├── all.dart │ ├── start.dart │ └── ping.dart ├── helpers.dart ├── logging.dart └── Config.dart ├── README.md ├── .gitignore ├── test └── tgbot_test.dart ├── pubspec.yaml ├── analysis_options.yaml ├── bin └── tgbot.dart └── pubspec.lock /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /lib/modules/all.dart: -------------------------------------------------------------------------------- 1 | export 'start.dart'; 2 | export 'ping.dart'; 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Yes 2 | 3 | Do not ask me what this is or how it works, it just does. -------------------------------------------------------------------------------- /lib/modules/start.dart: -------------------------------------------------------------------------------- 1 | void startCmd(message) { 2 | message.reply("hello"); 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | .env* 8 | -------------------------------------------------------------------------------- /lib/helpers.dart: -------------------------------------------------------------------------------- 1 | import 'package:teledart/telegram.dart'; 2 | 3 | Future getUsername(botToken) async => 4 | (await Telegram(botToken).getMe()).username; 5 | -------------------------------------------------------------------------------- /test/tgbot_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:tgbot/tgbot.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | test('calculate', () { 6 | expect(calculate(), 42); 7 | }); 8 | } 9 | -------------------------------------------------------------------------------- /lib/modules/ping.dart: -------------------------------------------------------------------------------- 1 | void pingCmd(message) { 2 | DateTime now = DateTime.now(); 3 | message.reply("Ping!"); 4 | DateTime newTime = DateTime.now(); 5 | int diff = newTime.millisecond - now.millisecond; 6 | message.reply("Pong! (${diff}ms)"); 7 | } 8 | -------------------------------------------------------------------------------- /lib/logging.dart: -------------------------------------------------------------------------------- 1 | import "package:logging/logging.dart" as logging; 2 | export "package:logging/logging.dart"; 3 | 4 | registerLogging(logging.Logger log) { 5 | log.onRecord.listen((logging.LogRecord record) { 6 | print("[" + record.time.toString() + "] " + record.message); 7 | }); 8 | } 9 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: tgbot 2 | description: A sample command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | 6 | environment: 7 | sdk: ">=2.15.1 <3.0.0" 8 | 9 | # dependencies: 10 | # path: ^1.8.0 11 | 12 | dev_dependencies: 13 | lints: ^1.0.0 14 | test: ^1.16.0 15 | dependencies: 16 | dotenv: ^3.0.0 17 | teledart: ^0.3.4 18 | logging: ^1.0.2 19 | -------------------------------------------------------------------------------- /lib/Config.dart: -------------------------------------------------------------------------------- 1 | import 'package:dotenv/dotenv.dart' show load, clean, isEveryDefined, env; 2 | 3 | class Config { 4 | String? botToken() { 5 | load(); 6 | return env['BOT_TOKEN']; 7 | } 8 | // if (isEveryDefined(['BOT_TOKEN'])) { 9 | // load(); 10 | // clean(); 11 | // } else { 12 | // throw Exception('BOT_TOKEN is not defined'); 13 | // } 14 | // return env['BOT_TOKEN']; 15 | 16 | } 17 | 18 | // String? Config() { 19 | // if (isEveryDefined(['BOT_TOKEN'])) { 20 | // load(); 21 | // clean(); 22 | // } else { 23 | // throw Exception('BOT_TOKEN is not defined'); 24 | // } 25 | // return env['BOT_TOKEN']; 26 | // } 27 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /bin/tgbot.dart: -------------------------------------------------------------------------------- 1 | // (c) @xditya 2 | // idk wtf this is, but it works 3 | 4 | import 'package:logging/logging.dart' as logging; 5 | import 'package:teledart/model.dart'; 6 | import 'package:teledart/teledart.dart'; 7 | import 'package:tgbot/Config.dart'; 8 | import 'package:tgbot/helpers.dart'; 9 | import 'package:tgbot/logging.dart'; 10 | import 'package:tgbot/modules/all.dart'; 11 | 12 | void main() async { 13 | logging.Logger log = logging.Logger(""); 14 | log.level = logging.Level.ALL; 15 | registerLogging(log); 16 | 17 | String? botToken = Config().botToken(); 18 | var username = await getUsername(botToken); 19 | var teledart = TeleDart(botToken.toString(), Event(username.toString())); 20 | teledart.start(); 21 | log.fine("Started"); 22 | 23 | // register commands 24 | teledart.onCommand('start').listen((message) => startCmd(message)); 25 | teledart.onCommand('ping').listen((message) => pingCmd(message)); 26 | teledart.onInlineQuery().listen((inlineQuery) => inlineQuery.answer([ 27 | InlineQueryResultArticle( 28 | id: 'ping', 29 | title: 'ping', 30 | input_message_content: InputTextMessageContent( 31 | message_text: '*pong*', parse_mode: 'MarkdownV2')), 32 | InlineQueryResultArticle( 33 | id: 'ding', 34 | title: 'ding', 35 | input_message_content: InputTextMessageContent( 36 | message_text: '*_dong_*', parse_mode: 'MarkdownV2')), 37 | ])); 38 | } 39 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "36.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "3.3.1" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.0" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.8.2" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "2.1.0" 39 | charcode: 40 | dependency: transitive 41 | description: 42 | name: charcode 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.3.1" 46 | collection: 47 | dependency: transitive 48 | description: 49 | name: collection 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "1.15.0" 53 | convert: 54 | dependency: transitive 55 | description: 56 | name: convert 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "3.0.1" 60 | coverage: 61 | dependency: transitive 62 | description: 63 | name: coverage 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "1.1.0" 67 | crypto: 68 | dependency: transitive 69 | description: 70 | name: crypto 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "3.0.1" 74 | dotenv: 75 | dependency: "direct main" 76 | description: 77 | name: dotenv 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "3.0.0" 81 | file: 82 | dependency: transitive 83 | description: 84 | name: file 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "6.1.2" 88 | frontend_server_client: 89 | dependency: transitive 90 | description: 91 | name: frontend_server_client 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "2.1.2" 95 | glob: 96 | dependency: transitive 97 | description: 98 | name: glob 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "2.0.2" 102 | http: 103 | dependency: transitive 104 | description: 105 | name: http 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "0.13.4" 109 | http_multi_server: 110 | dependency: transitive 111 | description: 112 | name: http_multi_server 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "3.2.0" 116 | http_parser: 117 | dependency: transitive 118 | description: 119 | name: http_parser 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "4.0.0" 123 | io: 124 | dependency: transitive 125 | description: 126 | name: io 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.0.3" 130 | js: 131 | dependency: transitive 132 | description: 133 | name: js 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "0.6.3" 137 | json_annotation: 138 | dependency: transitive 139 | description: 140 | name: json_annotation 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "4.4.0" 144 | lints: 145 | dependency: "direct dev" 146 | description: 147 | name: lints 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "1.0.1" 151 | logging: 152 | dependency: "direct main" 153 | description: 154 | name: logging 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "1.0.2" 158 | matcher: 159 | dependency: transitive 160 | description: 161 | name: matcher 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "0.12.11" 165 | meta: 166 | dependency: transitive 167 | description: 168 | name: meta 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.7.0" 172 | mime: 173 | dependency: transitive 174 | description: 175 | name: mime 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "1.0.1" 179 | node_preamble: 180 | dependency: transitive 181 | description: 182 | name: node_preamble 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "2.0.1" 186 | package_config: 187 | dependency: transitive 188 | description: 189 | name: package_config 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "2.0.2" 193 | path: 194 | dependency: transitive 195 | description: 196 | name: path 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "1.8.1" 200 | pool: 201 | dependency: transitive 202 | description: 203 | name: pool 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "1.5.0" 207 | pub_semver: 208 | dependency: transitive 209 | description: 210 | name: pub_semver 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "2.1.1" 214 | shelf: 215 | dependency: transitive 216 | description: 217 | name: shelf 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "1.2.0" 221 | shelf_packages_handler: 222 | dependency: transitive 223 | description: 224 | name: shelf_packages_handler 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "3.0.0" 228 | shelf_static: 229 | dependency: transitive 230 | description: 231 | name: shelf_static 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "1.1.0" 235 | shelf_web_socket: 236 | dependency: transitive 237 | description: 238 | name: shelf_web_socket 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "1.0.1" 242 | source_map_stack_trace: 243 | dependency: transitive 244 | description: 245 | name: source_map_stack_trace 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "2.1.0" 249 | source_maps: 250 | dependency: transitive 251 | description: 252 | name: source_maps 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "0.10.10" 256 | source_span: 257 | dependency: transitive 258 | description: 259 | name: source_span 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "1.8.2" 263 | stack_trace: 264 | dependency: transitive 265 | description: 266 | name: stack_trace 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "1.10.0" 270 | stream_channel: 271 | dependency: transitive 272 | description: 273 | name: stream_channel 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "2.1.0" 277 | string_scanner: 278 | dependency: transitive 279 | description: 280 | name: string_scanner 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "1.1.0" 284 | teledart: 285 | dependency: "direct main" 286 | description: 287 | name: teledart 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "0.3.4" 291 | term_glyph: 292 | dependency: transitive 293 | description: 294 | name: term_glyph 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "1.2.0" 298 | test: 299 | dependency: "direct dev" 300 | description: 301 | name: test 302 | url: "https://pub.dartlang.org" 303 | source: hosted 304 | version: "1.20.2" 305 | test_api: 306 | dependency: transitive 307 | description: 308 | name: test_api 309 | url: "https://pub.dartlang.org" 310 | source: hosted 311 | version: "0.4.9" 312 | test_core: 313 | dependency: transitive 314 | description: 315 | name: test_core 316 | url: "https://pub.dartlang.org" 317 | source: hosted 318 | version: "0.4.11" 319 | typed_data: 320 | dependency: transitive 321 | description: 322 | name: typed_data 323 | url: "https://pub.dartlang.org" 324 | source: hosted 325 | version: "1.3.0" 326 | vm_service: 327 | dependency: transitive 328 | description: 329 | name: vm_service 330 | url: "https://pub.dartlang.org" 331 | source: hosted 332 | version: "8.2.2" 333 | watcher: 334 | dependency: transitive 335 | description: 336 | name: watcher 337 | url: "https://pub.dartlang.org" 338 | source: hosted 339 | version: "1.0.1" 340 | web_socket_channel: 341 | dependency: transitive 342 | description: 343 | name: web_socket_channel 344 | url: "https://pub.dartlang.org" 345 | source: hosted 346 | version: "2.1.0" 347 | webkit_inspection_protocol: 348 | dependency: transitive 349 | description: 350 | name: webkit_inspection_protocol 351 | url: "https://pub.dartlang.org" 352 | source: hosted 353 | version: "1.0.0" 354 | yaml: 355 | dependency: transitive 356 | description: 357 | name: yaml 358 | url: "https://pub.dartlang.org" 359 | source: hosted 360 | version: "3.1.0" 361 | sdks: 362 | dart: ">=2.15.1 <3.0.0" 363 | --------------------------------------------------------------------------------