---
- name: Create config directory
  file:
    path: ~/.config/weechat
    state: directory
    mode: 0755

- name: Copy config files
  synchronize:
    src: weechat/
    dest: ~/.config/weechat/
    recursive: yes
    delete: yes

# Dependencies: weechat-lua, weechat-python
- name: Create lua and python plugins' directories
  file:
    path: '~/.local/share/weechat/{{ item }}/autoload'
    state: directory
    mode: 0755
  loop:
    - lua
    - python

- block:
    - name: Download emoji.lua script
      get_url:
        url: https://weechat.org/files/scripts/emoji.lua
        dest: '{{ script_location }}/emoji.lua'
        mode: 0644
        force: yes

    - name: Symlink emoji.lua to autoload directory
      file:
        src: ../emoji.lua
        dest: '{{ script_location }}/autoload/emoji.lua'
        state: link
  vars:
    script_location: ~/.local/share/weechat/lua
  tags: [ weechat-extend, weechat-emoji ]

- block:
    - name: Download autosort.py script
      get_url:
        url: https://weechat.org/files/scripts/autosort.py
        dest: '{{ script_location }}/autosort.py'
        mode: 0644
        force: yes

    - name: Symlink autosort.py to autoload directory
      file:
        src: ../autosort.py
        dest: '{{ script_location }}/autoload/autosort.py'
        state: link
  vars:
    script_location: ~/.local/share/weechat/python
  tags: [ weechat-extend, weechat-autosort ]

- block:
    - name: Download go.py script
      get_url:
        url: https://weechat.org/files/scripts/go.py
        dest: '{{ script_location }}/go.py'
        mode: 0644
        force: yes

    - name: Symlink go.py to autoload directory
      file:
        src: ../go.py
        dest: '{{ script_location }}/autoload/go.py'
        state: link
  vars:
    script_location: ~/.local/share/weechat/python
  tags: [ weechat-extend, weechat-go ]

- block:
    - name: Download grep.py script
      get_url:
        url: https://weechat.org/files/scripts/grep.py
        dest: '{{ script_location }}/grep.py'
        mode: 0644
        force: yes

    - name: Symlink grep.py to autoload directory
      file:
        src: ../grep.py
        dest: '{{ script_location }}/autoload/grep.py'
        state: link
  vars:
    script_location: ~/.local/share/weechat/python
  tags: [ weechat-extend, weechat-grep ]

- block:
    - name: Download notify_send.py script
      get_url:
        url: https://raw.githubusercontent.com/s3rvac/weechat-notify-send/master/notify_send.py
        dest: '{{ script_location }}/notify_send.py'
        mode: 0644
        force: yes

    - name: Symlink notify_send.py to autoload directory
      file:
        src: ../notify_send.py
        dest: '{{ script_location }}/autoload/notify_send.py'
        state: link
  vars:
    script_location: ~/.local/share/weechat/python
  tags: [ weechat-extend, weechat-notify-send ]

# Dependencies: py3-websocket-client
- block:
    - name: Download wee_slack.py script
      get_url:
        url: https://raw.githubusercontent.com/wee-slack/wee-slack/master/wee_slack.py
        dest: '{{ script_location }}/wee_slack.py'
        mode: 0644
        force: yes

    - name: Symlink wee_slack.py to autoload directory
      file:
        src: ../wee_slack.py
        dest: '{{ script_location }}/autoload/wee_slack.py'
        state: link
  vars:
    script_location: ~/.local/share/weechat/python
  tags: [ weechat-extend, weechat-slack ]
