mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-04-24 23:40:25 +02:00
added colored warnings in console_ui
* some extra spam prevention ( avoided bots from 4, 42, 142) and added a spam address * reduced initial days fetched if events are read from file
This commit is contained in:
parent
02a631faac
commit
202f1d14e2
@ -247,15 +247,22 @@ Future<void> main(List<String> arguments) async {
|
||||
// the default in case no arguments are given is:
|
||||
// get a user's events with all default users events
|
||||
// get mentions for user
|
||||
// get all kind 0, 3, 40, 42 events
|
||||
// get all kind 0, 3, 4x, 14x events
|
||||
|
||||
// then get the events of user-id's mentioned in p-tags of received events and the contact list
|
||||
// then display them all
|
||||
|
||||
getUserEvents(gListRelayUrls1, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor));
|
||||
getMultiUserEvents(gListRelayUrls1, gDefaultFollows, 1000, getSecondsDaysAgo(gDaysToGetEventsFor));
|
||||
getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor)); // from relay group 2
|
||||
getKindEvents([0, 3, 40, 42, 140, 141, 142], gListRelayUrls1, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor* 10));
|
||||
int daysToGetEventsFor = gDaysToGetEventsFor;
|
||||
|
||||
// if more than 1000 posts have already been read from the file, then don't get too many day's events. Only for last 3 days.
|
||||
if(numFilePosts > 1000) {
|
||||
daysToGetEventsFor = 3;
|
||||
}
|
||||
|
||||
getUserEvents(gListRelayUrls1, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor));
|
||||
getMultiUserEvents(gListRelayUrls1, gDefaultFollows, 1000, getSecondsDaysAgo(daysToGetEventsFor));
|
||||
getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor)); // from relay group 2
|
||||
getKindEvents([0, 3, 40, 42, 140, 141, 142], gListRelayUrls1, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor* 100)); // get all type 3 etc
|
||||
|
||||
// TODO get all 40 events, and then get all #e for them ( responses to them)
|
||||
|
||||
@ -283,11 +290,11 @@ Future<void> main(List<String> arguments) async {
|
||||
contacts.add(contact.id);
|
||||
});
|
||||
}
|
||||
getContactFeed(gListRelayUrls1, contacts, gLimitPerSubscription, getSecondsDaysAgo(2 * gDaysToGetEventsFor));
|
||||
getContactFeed(gListRelayUrls1, contacts, gLimitPerSubscription, getSecondsDaysAgo(2 * daysToGetEventsFor));
|
||||
|
||||
// calculate top mentioned ptags, and then get the events for those users
|
||||
List<String> pTags = getpTags(initialEvents, gMaxPtagsToGet);
|
||||
getMultiUserEvents(gListRelayUrls1, pTags, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor));
|
||||
getMultiUserEvents(gListRelayUrls1, pTags, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor));
|
||||
|
||||
stdout.write('Waiting for feed to come in..............');
|
||||
Future.delayed(const Duration(milliseconds: gDefaultNumWaitSeconds * 1), () {
|
||||
|
@ -281,9 +281,9 @@ void printProfile(Store node, String profilePubkey) {
|
||||
}
|
||||
|
||||
int showMenu(List<String> menuOptions, String menuName) {
|
||||
print("\n$menuName\n${getNumDashes(menuName.length)}");
|
||||
print('Pick an option:');
|
||||
while(true) {
|
||||
print("\n$menuName\n${getNumDashes(menuName.length)}");
|
||||
print('Pick an option:');
|
||||
for(int i = 0; i < menuOptions.length;i++) {
|
||||
print(" ${i+1}. ${menuOptions[i]}");
|
||||
}
|
||||
@ -306,7 +306,7 @@ int showMenu(List<String> menuOptions, String menuName) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
print("\nInvalid option. Kindly try again. The valid options are from 1 to ${menuOptions.length}\n");
|
||||
printWarning("\nInvalid option. Kindly try again. The valid options are from 1 to ${menuOptions.length}");
|
||||
|
||||
}
|
||||
}
|
||||
@ -341,11 +341,11 @@ Future<void> otherMenuUi(Store node) async {
|
||||
pubkey.forEach( (x) => print(" $x ( ${gKindONames[x]?.name} )"));
|
||||
if( pubkey.length > 1) {
|
||||
if( pubkey.length > 1) {
|
||||
print("Got multiple users with the same name. Try again, and try to type a more unique name or id-prefix");
|
||||
printWarning("Got multiple users with the same name. Try again, and/or type a more unique name or their full public keys.");
|
||||
}
|
||||
} else {
|
||||
if (pubkey.isEmpty ) {
|
||||
print("Could not find the user with that id or username.");
|
||||
printWarning("Could not find the user with that id or username.");
|
||||
}
|
||||
else {
|
||||
printProfile(node, pubkey.first);
|
||||
@ -371,7 +371,7 @@ Future<void> otherMenuUi(Store node) async {
|
||||
if( words != "") {
|
||||
bool onlyWords (Tree t) => t.treeSelectorHasWords(words.toLowerCase());
|
||||
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), onlyWords); // search for last gNumLastDays only
|
||||
} else print("Blank word entered. Try again.");
|
||||
} else printWarning("Blank word entered. Try again.");
|
||||
break;
|
||||
|
||||
|
||||
@ -388,7 +388,7 @@ Future<void> otherMenuUi(Store node) async {
|
||||
case 5: // follow new contact
|
||||
// in case the program was invoked with --pubkey, then user can't send messages
|
||||
if( userPrivateKey == "") {
|
||||
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
printWarning("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -401,15 +401,15 @@ Future<void> otherMenuUi(Store node) async {
|
||||
print(pubkey);
|
||||
if( pubkey.length > 1) {
|
||||
if( pubkey.length > 1) {
|
||||
print("Got multiple users with the same name. Try again, and type a more unique name or id-prefix");
|
||||
printWarning("Got multiple users with the same name. Try again, and type a more unique name or id-prefix");
|
||||
}
|
||||
} else {
|
||||
if (pubkey.isEmpty && userName.length != 64) {
|
||||
print("Could not find the user with that id or username. You can try again by providing the full 64 byte long hex public key.");
|
||||
printWarning("Could not find the user with that id or username. You can try again by providing the full 64 byte long hex public key.");
|
||||
}
|
||||
else {
|
||||
if( pubkey.isEmpty) {
|
||||
print("Could not find the user with that id or username in internal store/list. However, since the given id is 64 bytes long, taking that as hex public key and adding them as contact.");
|
||||
printWarning("Could not find the user with that id or username in internal store/list. However, since the given id is 64 bytes long, taking that as hex public key and adding them as contact.");
|
||||
pubkey.add(userName);
|
||||
}
|
||||
|
||||
@ -469,11 +469,11 @@ Future<void> otherMenuUi(Store node) async {
|
||||
gNumLastDays = int.parse(newNumDays);
|
||||
print("Changed number of days printed to $gNumLastDays");
|
||||
} on FormatException catch (e) {
|
||||
print("Invalid input. Kindly try again.");
|
||||
printWarning("Invalid input. Kindly try again.");
|
||||
if( gDebug > 0) print(" ${e.message}");
|
||||
continue;
|
||||
} on Exception catch (e) {
|
||||
print("Invalid input. Kindly try again.");
|
||||
printWarning("Invalid input. Kindly try again.");
|
||||
if( gDebug > 0) print(" ${e}");
|
||||
continue;
|
||||
}
|
||||
@ -490,7 +490,11 @@ Future<void> otherMenuUi(Store node) async {
|
||||
sendDeleteEvent(node, eventIdToDelete.first);
|
||||
await processAnyIncomingEvents(node, false); // get latest event, this takes 300 ms
|
||||
} else {
|
||||
print("Invalid Event Id(s) entered = {$eventIdToDelete}");
|
||||
if( eventIdToDelete.length == 0) {
|
||||
printWarning("Could not find the given event id. Kindly try again, by entering a 64 byte long hex event id, or by entering a unique prefix for the given event id.");
|
||||
} else {
|
||||
printWarning("Invalid Event Id(s). Kindly enter a more unique id.");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@ -609,7 +613,7 @@ Future<void> channelMenuUI(Store node) async {
|
||||
|
||||
// in case the program was invoked with --pubkey, then user can't send messages
|
||||
if( userPrivateKey == "") {
|
||||
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
printWarning("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
|
||||
} else {
|
||||
// send message to the given room
|
||||
@ -708,7 +712,7 @@ Future<void> updateEncryptedChannel(Store node, String channelId,
|
||||
|
||||
await processAnyIncomingEvents(node, false); // get latest event, this takes 300 ms
|
||||
} else {
|
||||
print("warning: could not find keys for the channel. Could not update.");
|
||||
printWarning("Could not find shared-secret keys for the channel. Could not update.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -748,7 +752,7 @@ Future<void> addUsersToEncryptedChannel(Store node, String fullChannelId, String
|
||||
|
||||
for(int i = 0; i < newPubKeys.length; i++) {
|
||||
if( newPubKeys[i].length != 64) {
|
||||
print("Invalid pubkey. The given pubkey should be 64 byte long.");
|
||||
printWarning("Invalid pubkey. The given pubkey should be 64 byte long.");
|
||||
continue;
|
||||
}
|
||||
toAdd.add(newPubKeys[i]);
|
||||
@ -772,7 +776,7 @@ Future<void> addUsersToEncryptedChannel(Store node, String fullChannelId, String
|
||||
print("sending kind 141 invites to: $participants");
|
||||
await updateEncryptedChannel(node, fullChannelId, channelName, channelAbout, channelPic, content, tags, participants, newParticipants);
|
||||
} else {
|
||||
print("no new users added. ");
|
||||
printWarning("Note: No new users added. ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -836,7 +840,7 @@ Future<void> encryptedChannelMenuUI(Store node) async {
|
||||
|
||||
// in case the program was invoked with --pubkey, then user can't send messages
|
||||
if( userPrivateKey == "") {
|
||||
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
printWarning("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey");
|
||||
} else {
|
||||
if( messageToSend.startsWith('/add ')) {
|
||||
await addUsersToEncryptedChannel(node, fullChannelId, messageToSend);
|
||||
@ -853,7 +857,7 @@ Future<void> encryptedChannelMenuUI(Store node) async {
|
||||
await sendChatMessage(node, fullChannelId, encryptedMessageToSend, "142");
|
||||
pageNum = 1; // reset it
|
||||
} else {
|
||||
printInColor("\nCould not encrypt and send message. Do confirm that you have access to this encrypted channel\n", redColor);
|
||||
printWarning("\nCould not encrypt and send message. Do confirm that you have access to this encrypted channel");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -922,7 +926,7 @@ Future<void> PrivateMenuUI(Store node) async {
|
||||
while(showChannelOption) {
|
||||
String fullChannelId = node.showDirectRoom(directRoomId, pageNum);
|
||||
if( fullChannelId == "") {
|
||||
print("Could not find the given direct room.");
|
||||
printWarning("Could not find the given direct room.");
|
||||
showChannelOption = false;
|
||||
break;
|
||||
}
|
||||
@ -940,12 +944,12 @@ Future<void> PrivateMenuUI(Store node) async {
|
||||
} else {
|
||||
// in case the program was invoked with --pubkey, then user can't send messages
|
||||
if( userPrivateKey == "") {
|
||||
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
printWarning("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
}
|
||||
// send message to the given room
|
||||
await sendDirectMessage(node, fullChannelId, messageToSend);
|
||||
await processAnyIncomingEvents(node, false); // get latest message
|
||||
print("in privateMenuUI: sent message");
|
||||
//print("in privateMenuUI: sent message");
|
||||
pageNum = 1; // reset it
|
||||
}
|
||||
}
|
||||
@ -1011,7 +1015,7 @@ Future<void> mainMenuUi(Store node) async {
|
||||
case 2:
|
||||
// in case the program was invoked with --pubkey, then user can't send messages
|
||||
if( userPrivateKey == "") {
|
||||
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
printWarning("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||
break;
|
||||
}
|
||||
stdout.write("Type comment to post/reply (type '+' to send a like): ");
|
||||
|
@ -16,6 +16,7 @@ int gDebug = 0;
|
||||
|
||||
String getStrInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?"$commentColor$s$gColorEndMarker":s;
|
||||
void printInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s$gColorEndMarker"):stdout.write(s);
|
||||
void printWarning(String s) => stdout.supportsAnsiEscapes ?stdout.write("$gWarningColor$s$gColorEndMarker\n"):stdout.write("$s\n");
|
||||
|
||||
|
||||
// translate
|
||||
|
@ -38,8 +38,8 @@ const String relayNostrInfo = 'wss://relay.nostr.info';
|
||||
String defaultServerUrl = "wss://relay.damus.io";
|
||||
|
||||
List<String> gListRelayUrls1 = [ defaultServerUrl,
|
||||
relayNostrInfo,
|
||||
"wss://nostr-verified.wellorder.net"
|
||||
relayNostrInfo
|
||||
// "wss://nostr-verified.wellorder.net"
|
||||
];
|
||||
|
||||
List<String> gListRelayUrls2 = [
|
||||
@ -196,7 +196,9 @@ List<String> gBots = [ "3b57518d02e6acfd5eb7198530b2e351e5a52278fb2499d14b66db2
|
||||
"f4161c88558700d23af18d8a6386eb7d7fed769048e1297811dcc34e86858fb2", // bitcoin_bot
|
||||
"105dfb7467b6286f573cae17146c55133d0dcc8d65e5239844214412218a6c36", // zerohedge
|
||||
"e89538241bf737327f80a9e31bb5771ccbe8a4508c04f1d1c0ce7336706f1bee", // Bitcoin news
|
||||
"6a9eb714c2889aa32e449cfbb7854bc9780feed4ff3d887e03910dcb22aa560a" // "bible bot"
|
||||
"6a9eb714c2889aa32e449cfbb7854bc9780feed4ff3d887e03910dcb22aa560a", // "bible bot"
|
||||
|
||||
"3104f98515b3aa147d55d9c2951e0f953b829d8724381d8f0d824125d7727634" // 42 spammer
|
||||
];
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// difficulty related settings
|
||||
|
@ -637,6 +637,10 @@ class Store {
|
||||
}
|
||||
|
||||
if( channel.lastUpdated < ce.eventData.createdAt) {
|
||||
if( participants.contains(userPublicKey) && !channel.participants.contains(userPublicKey) ) {
|
||||
//printInColor("\nReceived new invite to a new group with id: $chatRoomId\n", greenColor);
|
||||
}
|
||||
|
||||
channel.participants = participants;
|
||||
channel.lastUpdated = ce.eventData.createdAt;
|
||||
for(int i = 0; i < channel.messageIds.length; i++) {
|
||||
@ -928,6 +932,11 @@ class Store {
|
||||
return;
|
||||
}
|
||||
|
||||
//ignore bots
|
||||
if( [4, 42, 142].contains( newEvent.eventData.kind ) && gBots.contains(newEvent.eventData.pubkey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// handle reaction events and return if we could not find the reacted to. Continue otherwise to add this to notification set newEventIdsSet
|
||||
if( newEvent.eventData.kind == 7) {
|
||||
if( processReaction(newEvent, allChildEventsMap) == "") {
|
||||
@ -1960,6 +1969,9 @@ Store getTree(Set<Event> events) {
|
||||
return Store([], {}, [], [], [], temp);
|
||||
}
|
||||
|
||||
// remove bots from 42/142/4 messages
|
||||
events.removeWhere((event) => [42, 142, 4].contains(event.eventData.kind) && gBots.contains( event.eventData.pubkey) );
|
||||
|
||||
// remove all events other than kind 0 (meta data), 1(posts replies likes), 3 (contact list), 7(reactions), 40 and 42 (chat rooms)
|
||||
events.removeWhere( (event) => !Store.typesInEventMap.contains(event.eventData.kind));
|
||||
|
||||
|
@ -4,7 +4,7 @@ version: 0.0.9-beta
|
||||
homepage: https://github.com/vishalxl/nostr_console
|
||||
|
||||
# Release 0.0.9 - encrypted channels; fixes
|
||||
|
||||
#
|
||||
environment:
|
||||
sdk: '>=2.17.3 <3.0.0'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user