mod.rs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use std::collections::HashMap;
  19. use darkfi::Result;
  20. use crate::{
  21. settings::{Args, ChannelInfo, ContactInfo},
  22. PrivMsgEvent,
  23. };
  24. mod client;
  25. pub use client::IrcClient;
  26. mod server;
  27. pub use server::IrcServer;
  28. #[derive(Clone)]
  29. pub struct IrcConfig {
  30. // init bool
  31. pub is_nick_init: bool,
  32. pub is_user_init: bool,
  33. pub is_registered: bool,
  34. pub is_cap_end: bool,
  35. pub is_pass_init: bool,
  36. // user config
  37. pub nickname: String,
  38. pub password: String,
  39. pub private_key: Option<String>,
  40. pub capabilities: HashMap<String, bool>,
  41. // channels and contacts
  42. pub channels: HashMap<String, ChannelInfo>,
  43. pub contacts: HashMap<String, ContactInfo>,
  44. }
  45. impl IrcConfig {
  46. pub fn new(settings: &Args) -> Result<Self> {
  47. let password = settings.password.as_ref().unwrap_or(&String::new()).clone();
  48. let private_key = settings.private_key.clone();
  49. let mut channels = settings.channels.clone();
  50. for chan in settings.autojoin.iter() {
  51. if !channels.contains_key(chan) {
  52. channels.insert(chan.clone(), ChannelInfo::new());
  53. }
  54. }
  55. let contacts = settings.contacts.clone();
  56. let mut capabilities = HashMap::new();
  57. capabilities.insert("no-history".to_string(), false);
  58. Ok(Self {
  59. is_nick_init: false,
  60. is_user_init: false,
  61. is_registered: false,
  62. is_cap_end: true,
  63. is_pass_init: false,
  64. nickname: "anon".to_string(),
  65. password,
  66. channels,
  67. contacts,
  68. private_key,
  69. capabilities,
  70. })
  71. }
  72. }
  73. #[derive(Clone)]
  74. pub enum ClientSubMsg {
  75. Privmsg(PrivMsgEvent),
  76. Config(IrcConfig),
  77. }
  78. #[derive(Clone)]
  79. pub enum NotifierMsg {
  80. Privmsg(PrivMsgEvent),
  81. UpdateConfig,
  82. }