Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
committed Nov 15, 2022
0 parents commit 59fa0ba
Show file tree
Hide file tree
Showing 10 changed files with 710 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/funding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [azkadev]
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/

*.so
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Telegram Userbot dart simple

Telegram userbot dart simple,
> repository ini hanya untuk sumber belajar saja bagi orang yang ingin menggunakan bahasa code dart
> Silahkan tonton video speed code ya:) biar userbot ini bisa jalan
[![](https://img.youtube.com/vi/YEFM0ITlLNk/hqdefault.jpg)](https://www.youtube.com/watch?v=YEFM0ITlLNk)
30 changes: 30 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
175 changes: 175 additions & 0 deletions bin/telegram_userbot_dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// ignore_for_file: non_constant_identifier_names

import 'dart:convert';
import 'dart:io';
import 'package:telegram_client/scheme/tdlib_scheme.dart' as tdlib_scheme;
import 'package:telegram_client/tdlib/tdlib.dart';
import 'package:telegram_client/telegram_client.dart';
import 'package:path/path.dart' as p;
void main(List<String> arguments) async {
print("started telegram client");
int api_id = 0;

/// get api_id in https://my.telegram.org/auth
String api_hash = "";

/// get api_hash in https://my.telegram.org/auth
/// compile first https://tdlib.github.io/td/build.html?language=dart
String path_tdlib = "./libtdjson.so";
Directory tg_dir = Directory(p.join(Directory.current.path, "db_userbot"));

Tdlib tg = Tdlib(
path_tdlib,
clientOption: {
"api_id": api_id,
"api_hash": api_hash,
"database_directory": tg_dir.path,
"files_directory": tg_dir.path,
},
);

tg.on(tg.event_update, (UpdateTd update) async {
// print(json.encode(update.raw));

/// authorization update
if (update.raw["@type"] == "updateAuthorizationState") {
if (update.raw["authorization_state"] is Map) {
var authStateType = update.raw["authorization_state"]["@type"];

/// init tdlib parameters
await tg.initClient(
update,
clientId: update.client_id,
tdlibParameters: update.client_option,
isVoid: true,
);

if (authStateType == "authorizationStateLoggingOut") {}
if (authStateType == "authorizationStateClosed") {
print("close: ${update.client_id}");
tg.exitClient(update.client_id);
}
if (authStateType == "authorizationStateWaitPhoneNumber") {
stdout.write("Phone number: ");
String phone_number = stdin.readLineSync().toString();

/// use this if tdlib function not found method
// await tg.invoke(
// "setAuthenticationPhoneNumber",
// parameters: {
// "phone_number": phone_number,
// },
// clientId: update.client_id,
// );

/// use call api if you can't see official docs
await tg.callApi(
tdlibFunction: tdlib_scheme.TdlibFunction.setAuthenticationPhoneNumber(
phone_number: phone_number,
),
clientId: update.client_id, // add this if your project more one client
);

/// use this if you wan't login as bot
// await tg.callApi(
// tdlibFunction: TdlibFunction.checkAuthenticationBotToken(
// token: "1213141541:samksamksmaksmak",
// ),
// clientId: update.client_id, // add this if your project more one client
// );

}
if (authStateType == "authorizationStateWaitCode") {
stdout.write("Code: ");
String code = stdin.readLineSync().toString();
// await tg.invoke(
// "checkAuthenticationCode",
// parameters: {
// "code": code,
// },
// clientId: update.client_id,
// );

await tg.callApi(
tdlibFunction: tdlib_scheme.TdlibFunction.checkAuthenticationCode(
code: code,
),
clientId: update.client_id, // add this if your project more one client
);
}
if (authStateType == "authorizationStateWaitPassword") {
stdout.write("Password: ");
String password = stdin.readLineSync().toString();
// await tg.invoke(
// "checkAuthenticationPassword",
// parameters: {
// "password": password,
// },
// clientId: update.client_id,
// );

await tg.callApi(
tdlibFunction: tdlib_scheme.TdlibFunction.checkAuthenticationPassword(
password: password,
),
clientId: update.client_id, // add this if your project more one client
);
}

if (authStateType == "authorizationStateReady") {
Map get_me = await tg.getMe(clientId: update.client_id);
print(get_me);
}
}
}

if (update.raw["@type"] == "updateNewMessage") {
if (update.raw["message"] is Map) {
/// tdlib scheme is not full real because i generate file origin to dart with my script but you can still use
tdlib_scheme.Message message = tdlib_scheme.Message(update.raw["message"]);
int chat_id = message.chat_id ?? 0;
if (message.content.special_type == "messageText") {
if (update.raw["message"]["content"]["text"] is Map && update.raw["message"]["content"]["text"]["text"] is String) {
String text = (update.raw["message"]["content"]["text"]["text"] as String);

if (RegExp(r"^/alive$", caseSensitive: false).hasMatch(text)) {
// / use request if you wan't call api more easy and pretty like telegram bot api
await tg.callApi(
tdlibFunction: tdlib_scheme.TdlibFunction.sendMessage(
chat_id: chat_id,
options: tdlib_scheme.MessageSendOptions.create(from_background: true),
input_message_content: tdlib_scheme.InputMessageContent.create(text: tdlib_scheme.FormattedText.create(text: "Native Tdlib Scheme")),
),
);

return await tg.request(
"sendMessage",
parameters: {
"chat_id": chat_id,
"text": "alive telegram client @azkadev",
},
clientId: update.client_id,
);
}
if (RegExp(r"^/ping$", caseSensitive: false).hasMatch(text)) {

return await tg.request(
"sendMessage",
parameters: {
"chat_id": chat_id,
"text": "Pong bang",
},
clientId: update.client_id,
);
}

}
}
}
}
});

await tg.initIsolate();
print("succes init isolate");
}
3 changes: 3 additions & 0 deletions lib/telegram_userbot_dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int calculate() {
return 6 * 7;
}
Loading

0 comments on commit 59fa0ba

Please sign in to comment.